views:

232

answers:

2

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.

A: 

That makes no sense as to why it only moves when it's released, is there nothing else interfering with it elsewhere such as another keyboard input hidden somewhere? I only ask as it could be that another keyboard input statement in conflicting with another and causing the problem.

Jamie Keeling
updated question with more info.
Rosarch
+1  A: 

Regarding your update: In XNA, depending on how you've situated your camera, negative Y is up. If you want the rocket to go up, you have to apply a force in that direction.

Jeff