Help me out getting things to move from user input

I have a simple world set up with an object and a ground plane.

Everything works. If I enable gravity the object falls and bounces off the ground plane.

I want to make sort of a little spaceship that I can fly around using the arrow keys. I have this all set up. What I need to figure out is which property to use to make the body move.

I created a new b2Body using World.CreateBody. I saved this body in a variable and am using this as my target.

I tried using SetLinearVelocity(). But this seems to produce no result.

_ship.SetLinearVelocity( new b2Vec2( 0, 2 ) );

Looking at this now. I'm realizing the number 2 should probably be a lot smaller if the units are meters.
You use
Code:
body.ApplyImpulse(impulse:b2Vec2, point:b2Vec2):void

or
Code:
body.ApplyForce(impulse:b2Vec2, point:b2Vec2):void


Where impulse is just like the gravity vector, and for the point you probably want to push it at the center of mass, which you can get by:

Code:
body.GetWorldCenter()


So you'd probably end up with something like:

Code:
body.ApplyImpulse(new b2Vec2([as per controls]), new b2Vec2(body.GetWorldCenter().x, body.GetWorldCenter().y))


or prettier 😳

One problem I had (in truth, still have), with this was the two coordinate systems. You may trip with the whole physScale thing. Watch the step 😉

Edit: code
Thanks that was really helpful.

As a second question, how can I add rotation to an object. Let's say I want it to turn left or right when I press the left or right arrow?

My plan is to get the ship to rotate left and right then create a thrust vector based on the angle.
Looks like b2Body.ApplyTorque( number ), gets the body to rotate...
Right, but it's hard to control I'd say.

You may want to take a look at
Code:
SetXForm(position:b2Vec2, angle:Number):Boolean


Very easy to use, and you can of course get back the angle for the thrust with body.GetAngle().

Edit: Took me a while to find this one too. They should have just named it 'SetPosition'. That way we all know what we're talking about.

Original thread: https://box2d.org/forum/viewtopic.php?t=4138