PDA

View Full Version : ODE Space Physics

technomage
07-10-2005, 09:50 AM
Hi everyone, as WILL is away I figured I' d post a little problem. :D

i have a nice space sim I've developing. The ships are controled by thrusters which apply forces to the ODE body at certain positions to get the effect of actually flying the ship. I also have the main engines which apply force in the +ve Z direction (relative to the body). This all works fine. I have also implemented a flight control system which will reduce the angular velocity to 0 if the controls are released.

Now the question is this...

I want to limit the maximum linear and angualr velocity (in all directions) to a set value to ensure that the ship doesn't spin totally out of control. Now I could do this by manually setting the velocity is it has reached the maximum but the ODE documentaion advises against this. The other option would be to work out the forces needed to stop the craft accelerating any more. I'm not sure about any other possible solutions.

Anyone got any thoughts on this?

Dean

tux
07-10-2005, 11:45 AM
heres how im doing it for my physics...

var
LVelocity: TRAGEVector3;
LCurVel: TRAGEVector3;
LLength: Single;
LMass: Single;
LTimeSlice: Single;

...

LCurVel := rpGetBodyVelocity(FPhysicsWorld, LPhysicsBallIndex);
LLength := VectorLength(LCurVel);

if LLength > GMaxSpeed then
Begin
LMass := rpGetBodyMass(FPhysicsWorld, LPhysicsBallIndex);
LTimeSlice := rpGetWorldTimeSlice(FPhysicsWorld);

LVelocity := VectorScale(LCurVel, GMaxSpeed / LLength);
rpSetBodyForces(FPhysicsWorld, LPhysicsBallIndex,
LMass * ((LVelocity[0] - LCurVel[0]) / LTimeSlice),
0, // dont change Y, otherwise it flies off if it goes up a ramp
LMass * ((LVelocity[2] - LCurVel[2]) / LTimeSlice));
end;

time slice is in seconds, and it uses inverse dynamics to set the speed (and its pretty acuret).

gMaxSpeed is in meters per second

forces needed to get speed = Mass * (desired velocity - current velocity) / time step

technomage
08-10-2005, 10:24 AM
thanks tux, I'll look into that. Are you using ODE as an underlying physics engine :?:

Dean

tux
08-10-2005, 10:57 AM
no, im using newton.

tux
08-10-2005, 10:59 AM
another thing you might want to look into is adding a damping force in the inverted direction of the thrusters, that might be better for you instead of scaling the velocity (could produce un wanted behavure in 3d physics)