I'm trying to move a body:
if (ks.IsKeyDown(Keys.Up)) {
rocket.ApplyImpulse(new Box2DX.Common.Vec2(0, 30f), rocket.GetPosition());
}
Oddly, the body only moves when the key is released. Why is this? I've been looking at the manual but can't figure it out.
When I remove the conditional, and just have the applyImpulse()
call in Step()
, the rocket continually has the animation of thrusters but never actually moves. (As if I had been holding down the Up key the entire time.)
Looks like what I really need to get this working is a better understanding of what the first argument to applyImpulse()
does:
new Box2DX.Common.Vec2(0, 30f)
What is the significance of the two values in the vector?
UPDATE This works much better:
rocket.ApplyImpulse(new Box2DX.Common.Vec2(0, -1), rocket.GetPosition());
It looks like if the second value in the force vector is negative, the object rises on the screen. Before, the impulse applied was just slamming it into the floor. When I released the key, it would sometimes bounce back, if the impulse had been strong enough.