How do I get magnitude variable of the box2d physics?

Get help using Construct 2

Post » Sun Feb 07, 2016 4:14 pm

I want comparing magnitude variable with a another local variable for the checking a if statement.
B
14
S
2
Posts: 66
Reputation: 776

Post » Sun Feb 07, 2016 4:48 pm

Why dont come answer for this question maybe nobody dont know what is magnitude or why?
Sory guys but i now are very fustraded. 😢
B
14
S
2
Posts: 66
Reputation: 776

Post » Sun Feb 07, 2016 10:15 pm

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:
how-do-i-get-the-overall-velocity-physics_t121255
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Sun Feb 07, 2016 11:39 pm

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?
B
14
S
2
Posts: 66
Reputation: 776

Post » Mon Feb 08, 2016 12:24 am

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.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Mon Feb 08, 2016 1:05 am

Understand thanks your answer but in the c2 box2d physics why not maked defaultly magnitude and sqrmagnitude for a better physics? And in the unity why is? Magnitude is a often used members.
I do not like to code and math therefore I like c2 but I often feel that c2 expressions and built in members very few.
B
14
S
2
Posts: 66
Reputation: 776


Return to How do I....?

Who is online

Users browsing this forum: jkmalau, MoscowModder, terence951, vegapomme27, Yahoo [Bot] and 9 guests