[HELP]Platform moving, my force callback and strange effect

misiek

18-08-2009 08:53:28

Hello,
I'm working on platform game, and have a problem with platform moving. My force and torque callback for platforms:

void CPlatform::forceAndTorqueCallback(OgreNewt::Body* body)
{
Real dt = mNewtWorld->getTimeStep();
Vector3 pos;
Quaternion orient;

body->getPositionOrientation(pos, orient);

// Vector3 CWaypoint::update(Real delta) returns the point where platform should be placed after delta time update
Vector3 ds = mWaypoint->update(dt) - pos; // that is translation vector

// finally set force
body->setForce( -body->getVelocity() * mPlatformMass /dt // to stop
+ 2 * ds * mPlatformMass / (dt * dt) ); // to translate
}

At the beginning of simulation it looks nice but bit by bit platform is shaking till it fall out of the OgreNewt world.

Sorry of my English! :)

melven

21-08-2009 14:18:33

You can use a spring-damping system for smooth movement:

Real linearSpringK = 400; // spring coefficient, higher values will make the body move faster to the new position
Real relationKoefficient = 1; // if this is set to higher values, it overshoots a bit...
Real linearDampingK = relationKoefficient * 2.0 * sqrt(linearSpringK);
// Vector3 velocity: current velocity of the body
// Vector3 diff: translation vector
Vector3 springAcc = - linearSpringK * diff - linearDampingK * velocity;
// then set the force:
body->setForce( springAcc * mass );


I use this code to create a smooth camera movement, you can play a bit with the parameters until it fits your requirements...

misiek

28-08-2009 22:36:33

Thanks melven, didn't know about that.
But I still looking for bug in my force calculation:
to stop the body with MASS mass, during DT time, which has VEL velocity:
acceleration = force / MASS,
acceleration = -VEL / DT,
force / MASS = -VEL / DT,
force = -VEL * MASS / DT
to move the body with MASS mass, during DT time, along DS translation vector:
DS = acceleration2 * DT * DT / 2,
DS = force2 / MASS * DT * DT / 2,
force2 = DS * MASS * 2 / DT / DT
please someone check it...
It works fine when force2 = DS * MASS / DT / DT (without multiplication by 2) - does anybody know why?

At least, I want to ask about OgreNewt simulations with non constant update time (like I'm doing in code above) - are there any problems to achieve fluctuation and the same speed of objects with different fps (because I update OgreNewt world every frame in FrameListener).

Thanks a lot!