This project has moved. For the latest updates, please go here.

Please help me fly

Topics: Developer Forum
Jun 25, 2009 at 12:52 PM

Hi All,

I have code to launch a projectile in an arc using 1 body, 1 geom on a texture2d and using ApplyImpulse()

The arc is perfect but I can't for the life of me get the object to rotate on the path....imagine a spear or arrow.

Is there a simple way to do this?

Many Thanks in advance


Jun 25, 2009 at 1:16 PM
Edited Jun 25, 2009 at 1:19 PM

You can get the velocity of the body with body.LinearVelocity. This will give you the vector of the velocity of the body at that time. Then rotate the body acording to this vector :)

(try the Math.acos, Math.asin or Math.atan for retrieving the angle)

Jun 25, 2009 at 2:05 PM


Thanks I am heading in the right direction but could you possibly give a working code for getting the angle I seem to suddenly spin and head for the ground :(



Jun 25, 2009 at 2:12 PM
Edited Jun 25, 2009 at 2:15 PM

No problem, I think that should be (not tested, just guessing):

body.Rotation = Math.Atan(body.LinearVelocity.Y / body.LinearVelocity.X)

Edit: Just check before updating the rotation that body.LinearVelocity.X != 0



Jun 25, 2009 at 2:18 PM

Thank you :)

All going where it should much appreciated :)