eugene.litvinov Posted February 16, 2011 Share Posted February 16, 2011 I have object, that must levitate. I prepare scene, where object (die) in the air, see screenshot: 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
frustum Posted February 17, 2011 Share Posted February 17, 2011 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
eugene.litvinov Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks, it works: float G = 9.81f; vec3 force; force.z = G * body.getMass(); body.addForce(force); Body was levitate and no change his position. Link to comment
Recommended Posts