Dynamics of a rocket

Topics: Developer Forum, User Forum
Jul 12, 2010 at 2:54 PM
Edited Jul 13, 2010 at 2:24 PM

I would like to add "rocket"-like movement for certain objects. I know how to implement this using a kinematic body, but I want to implement it using a dynamic body, but I'm sort of lost on how to implement this. To simplify things, I don't need the dynamics to rotate the geometry, just to affect the velocity of the body. I'm using a circle fixture that is set to not rotate. I'm not even sure what the best abstraction should be. Conceptually, I have the direction the body is currently moving, a direction I want it to go, and a value representing how fast I want it to change direction, while keeping speed relatively constant (small variations are acceptable). I could use this abstraction directly, or use this as an abstraction over another abstraction, which would be a "rudder" value which controlled how fast the object changed directions (either clockwise or counter clockwise). Has anyone implemented this before and have any pointers? What kind of forces should I apply to the body to simulate the movement I'm looking for? PS: I would also like to be able to adjust the "thrust" of the rocket on the fly. Thanks for the help. - Jeremy

Edit: I also asked this question on stackoverflow and got a pretty good answer. Here is some simple test code I wrote to test the answer (for simplicity, assuming fixed time step and object mass of 1.0, and that object is always pointed in the same direction as it is moving):

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
        float dc = 0.001f;
        float lc = 0.025f;
        float angle = MathHelper.ToRadians(45);
        Vector2 vel = new Vector2(1, 0);
        Vector2 pos = new Vector2(0, 0);
        for (int i = 0; i < 200; i++)
            Vector2 drag = vel * angle * dc;
            Vector2 sideForce = angle * lc * vel;
            //sideForce = new Vector2(sideForce.Y, -sideForce.X); // rotate 90 degrees CW
            sideForce = new Vector2(-sideForce.Y, sideForce.X); // rotate 90 degrees CCW
            vel = vel + (-drag) + sideForce;
            pos = pos + vel;
            if(i % 10 == 0)
                System.Console.WriteLine("{0}\t{1}\t{2}", pos.X, pos.Y, vel.Length());