0 Favourites

# How do I get magnitude variable of the box2d physics?

• 6 posts
• I want comparing magnitude variable with a another local variable for the checking a if statement.

• Why dont come answer for this question maybe nobody dont know what is magnitude or why?

Sory guys but i now are very fustraded. 😢

• It isn't really reasonable to want an answer within a half hour. Your question isn't clear, do you mean you want to get the speed of an object? You can calculate it with the Pythagorean theorem and the x and y velocities. Maybe this topic may help:

• I dont want math.

in unity game engine is possible.

float maxcollisionpower = 8f;

float sqrmaxcollisionpower = maxcollisionpower * maxcollisionpower;

if (obj.velocity.sqrmagnitude == sqrmaxcollisionpower)

I this want in c2. Possible?

• But what you replied with is math too, and actually it's basically the the same as what I referenced.

Velocity is a vector. Or basically it has a x and y value. The magnitude of a vector is it's length which can be calculated with the Pythagorean theorem:

sqrt(sprite.physics.velocityX^2 + sprite.physics.velocityY^2)

Or just use the distance expression, which does the same thing:

distance(0, 0, sprite.physics.velocityX, sprite.physics.velocityY)

In your example the "sqr" means the value is squared so that would be this:

sprite.physics.velocityX^2 + sprite.physics.velocityY^2

or this

distance(0, 0, sprite.physics.velocityX, sprite.physics.velocityY)^2

just repace "obj.velocity.sqrmagnitude" with one of those.