Jump to content

addForce() to BodyRigid instance


photo

Recommended Posts

I have object, that must levitate. I prepare scene, where object (die) in the air, see screenshot:

post-151-0-02525900-1297857611_thumb.jpg

When I close editor I use engine.game.setEnabled(true); and start add force to the object:

float G = 9.81f;

void update()
{
float ifps = engine.game.getIFps() / engine.physics.getIFps() * engine.physics.getScale(); // this is I get in samples/common/physics.h - how I understand, this is time, that we spend on one frame?

BodyRigid body = meshDie2.getBodyRigid(); // get our physical body
vec3 pos = meshDie2.getPosition();

vec3 force;
force.z = G * body.getMass(); // add force, that must oppose to gravity force

body.addForce(force * ifps * ifps); // add this oppose force with ifps (from samples/common/physics.h)
}

 

In this realization object fly away on Z-direction (in sky), instead of levitation. Could you explain, how add force to object for compensation gravity force and object could stay (fly) on his default position? Thanks.

Link to comment

Accumulation of physical forces inside the update() function is always incorrect because of non-fixed rendering fps.

There is a flush() function which is calls every physical simulation step.

Look through physical samples how to use this function.

Link to comment
×
×
  • Create New...