Game Development Community

Acceleration-Speed based Movement Physics

by Mike Kuklinski · in Torque Game Engine · 05/14/2006 (8:30 pm) · 3 replies

A big problem I have noticed with the current system for vehicles, the rigid-body physics system, is that I cannot get physics similar to that of Wing Commander or Starlancer...

I seem to be required to tinker with a jet force and a drag variable in order to get a maximum speed, and even then I cannot control acceleration..

What I want to be able to do is set 2 distinct items: acceleration (m/s^2), and maximum speed (m/s). From that, I want to automatically determine what the drag should be to slow it down when it is does accelerating, etc... however, I seem to be unable to do this with the current rigid body system --- any ideas?

#1
05/26/2006 (9:35 am)
Are you still looking for a solution to this? Because I can probably be of some assistance. I created something very similar for my vehicles, and it wasn't too difficult. The approach I used was to reduce the thrust as the vehicle approached the maximum defined speed.

The downside to this approach is that the "actual" maximum speed is always somewhat less than the "maxSpeed" value that you define, due to drag. (I kept a constant drag value. The vehicle will reach the defined "maxSpeed" only if the drag is set to 0.)

On the plus side though, the math was simple, and it does effectively limit the vehicle's maximum speed (independent of its acceleration force). Also, I am still free to set the drag value independently, resulting in more or less "slide" affect when you release the throttle. This worked well for my purposes.

This was all done in my own vehicle class, which differs significantly from the stock Torque vehicles. I don't know how easy it would be to integrate such a system into a stock vehicle class, but I can look into it. I doubt it would be difficult.
#2
05/29/2006 (8:44 am)
Hi Scott,

Your solution sounds like it may be close to what I'm looking for - see this thread. And you have slide... I'd definately like to see how you've done this if possible. I've just been on holiday, my maths head hasn't come back yet.
#3
05/30/2006 (2:05 pm)
Simple enough: Take your thrust vector, normalize it, then dot with linVelocity. That will give you your velocity along the thrust vector. Divide that by a maxSpeed value and clamp the result to a range 0 to 1. Now you have a "thrustFalloff" value that is 0 when the vehicle is not traveling in the direction of thrust, increasing to 1 when the vehicle has reached maxSpeed in the direction of thrust. From here you can simply multiply the thrust by "1 - thrustFalloff" before adding it to "force". (This would be done in YourVehicle::updateForces, by the way).

My implementation looks like this:
// Determine thrust falloff
      F32 falloffFactor = 1.0f;
         if (maxSpeed > 0.001f) {
            VectorF thrustDir = linThrust;
            thrustDir.normalize();
            falloffFactor = mDot(thrustDir, mRigid.linVelocity) / maxSpeed;
            falloffFactor = mClampF(falloffFactor, 0.0f, 1.0f);
            //falloffFactor = 1.0f - falloffFactor;
            falloffFactor = 1.0f - (falloffFactor * falloffFactor);
         }
      linThrust *= falloffFactor;

      // And apply
      force += linThrust;

Note that if you're working off FlyingVehicle, "maneuvering" and "jet" forces are directly applied to "force". You'll have to rearrange the code to collect those forces in a separate VectorF before applying them to "force". In my code "linThrust" is the VectorF which I used for that purpose.

Note also that I decide to square "falloffFactor" because I thought it gave a better "acceleration curve", otherwise it's just a linear falloff. It's quick, it's easy, it works. Ideally I would like to have more control over the acceleration curve, perhaps using a Bezier curve function; but that's a project for another day.