This project is read-only.

Forces and Velocities

Aug 7, 2008 at 8:44 PM
I'm currently playing around with the engine, and I'm unsure of whats wrong with my main actor.

I can add it to the world, view it from a free look camera, and change its velocity directly i.e. guy.PhysicsBody.PhysicsBody.Velocity = ...
After changing his velocity like this directly, I can call UpdatePosition() and his position is correctly updated and drawn on-screen.

But when I call guy.PhysicsBody.PhysicsBody.UpdateVelocity(), his position moves out towards infinite in all directions.  This happens whether or not I apply a force to the actor.  I've set his mass to be a range of numbers with no noticeable effect.  As soon as the window loads, his position is at infinite/NAN.

Is there something I'm not doing when I set up the actor?
Aug 13, 2008 at 9:38 PM
You shouldn't need to call UpdatePosition() and UpdateVelocity(), all that is called by the physics engine. Just setting the velocity on the actor has worked for me.

Otherwise, you will want to create a class that inherits from Controller and have it reference the PhysicsBody.PhysicsBody, then apply forces to it in the UpdateController() method. ie:

public class VelocityController : Controller
     Body body;

     public VelocityController(Body body)
          this.body = body;

     public override void UpdateController(float dt)
          // Apply forces to the body (body.AddWorldForce, etc.)