This project has moved and is read-only. For the latest updates, please go here.

Moving Body In Direction It Is Facing

Topics: Developer Forum
Dec 11, 2013 at 11:09 AM

Basically I have a ship, like in a space shooter. I want to be able to move the ship in the direction that it is facing. So if I rotate the ship 45 degrees clockwise, and I apply a force to the ship to move it, it will move in the direction its facing which is 45 degrees. I have done some research but really couldn't find what I needed to make this happen.

I know how to get this to happen by just getting the current linear velocity, calculating a new vector, then just saving it to the bodies linear velocity property, but that is not recommended in farseer for realistic simulations.

Any help would be great.
Dec 11, 2013 at 8:19 PM
Try this
   _body.ApplyForce(AngleToVector(_body.Rotation), _body.WorldCenter);

        public Vector2 AngleToVector(float angle)
            return new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle));
Dec 12, 2013 at 11:02 AM
Thanks again HAL!! It works well except I would like to put a limit to the ships velocities. A speed limit basically. Any ideas?
Dec 12, 2013 at 8:58 PM
Hmm not sure, never had to do it but I'd look at the LinearDamping variable on the body. Then play around with the dampening, density and force applied to get the right feel for what you want.
Dec 12, 2013 at 9:56 PM
I will look into it. Thanks again. :)
Dec 13, 2013 at 1:40 AM

Using the linear damping works perfectly. Thanks for all your help!! Take care.