Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom polygon attached to a body, which looks like this: Custom Polygon Attached To Body What I am trying to accomplish is getting the body to move according to wherever the tip of the body is. So far this is what I've tried:

        if (ks.IsKeyDown(Keys.Up))
            body.ApplyForce(new Vector2(0, -20),body.GetLocalPoint(new Vector2(0,0)));

        if (ks.IsKeyDown(Keys.Left))
        if (ks.IsKeyDown(Keys.Right))

The body rotates fine - but when I try making the body accelerate according to the tip of the body - assuming I have specified the tip correctly(I am pretty sure I haven't), it just spins around, as if I have applied Torque to it. Can anyone point me in the right direction of how to fix this problem?

share|improve this question
possible duplicate of Move sprite in the direction it is facing? – Byte56 Oct 9 '12 at 23:59
Hmm..I don't think there is anything wrong with the torque because as far as I know, the ApplyTorque function requires large values. – Grey Oct 10 '12 at 0:20
I implemented your solution - but it seems I took a wrong turn somewhere: When I press the up-key it rotates very fast. Instead of moving in a straight line according to the tip of the body :/ – Grey Oct 10 '12 at 1:23
Rotates in place and sort of moves down diagonally. – Grey Oct 10 '12 at 4:33
Bummer. OK we'll I've cleaned up my unuseful comments. Good luck! – Byte56 Oct 10 '12 at 15:57
up vote 1 down vote accepted

Apply the force to the objects center as suggested by Gajoo. Conviently WorldCenter is a property of the body class so.

Body.ApplyForce(forceDirection, Body.WorldCenter);

Also if you want to move the body in a specific direction you need to apply the force in that direction so "new Vector2(0, -20)" doesn't make any sense. To create a the unit vector that faces int the same direction as your body do the below.

var forceDirection = Vector2.UnitY;
var test = Matrix.CreateFromAxisAngle(new Vector3(0, 0, 1), Body.Rotation);
forceDirection = Vector2.Transform(facing, test);

Now simply scale the forceDirection vector to alter the speed.

share|improve this answer

ApplyForce does not work like that. The problem is you are always applying a force to the left down corner of your shape, with always same direction. here is a picture explaining it (I might be wrong about the corner the force is applied to but the idea is the same):

enter image description here

to fix this issue you should always apply the force to the center of your ship, and the rest is the same as explained in byte56 suggested. It means you need to rotate force vector yourself and then pass it to farseer

share|improve this answer
direction = body.GetWorldVector(new Vector2(0,1));

When using Farseer Physics calculating the direction isn't so hard. If your body starts off with it's tip point upwards you can find the direction by simply updating direction(as shown above) in your update loop, and then when the user presses the up-key simply apply(after calculating the velocity's as shown in this questions answered by Byte56:

body.ApplyForce(velocity * -100); 

Play with the values to get the desired output :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.