Box jumps of ground for no reason

User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

Box jumps of ground for no reason

Post by Dragonlord »

Got the first testing version to run but with a strange effect. If i use a time step of 0.01 my box rests on the ground and from time to time suddenly jumps up high into the sky. Has this a connection to the used time step? I use the following setup:

Code: Select all

		CcdConstructionInfo constrInfo;
		constrInfo.m_friction = 0.2f;
		constrInfo.m_linearDamping = 0.2f;
		constrInfo.m_angularDamping = 0.1f;
		constrInfo.m_MotionState = motionState;
		constrInfo.m_gravity = SimdVector3( 0.0f, 0.0f, 0.0f );
		constrInfo.m_localInertiaTensor = SimdVector3( 0.0f, 0.0f, 0.0f );
		constrInfo.m_mass = 1.0f;
		pShape->CalculateLocalInertia( 0.0f, localInertia );
		constrInfo.m_localInertiaTensor = localInertia;
		constrInfo.m_collisionShape = pShape;
		pPhyCtrl = new CcdPhysicsController( constrInfo );
	pPhyCtrl->setPosition( position.x, position.y, position.z );
	pPhyCtrl->SetLinearVelocity( velocity.x, velocity.y, velocity.z, false );
	pPhyCtrl->GetRigidBody()->m_ccdSquareMotionTreshold = 0.001f;
	pPhyCtrl->GetRigidBody()->m_ccdSweptShereRadius = 0.001f;
The shape is a simple box of 0.05m extends. If I use a larger time step ( for example the entire elapsed time since the last update ) the jumping does no appear but the box starts bobbing on the ground sinking into it sometimes up to half the height.

Any ideas what could be wrong or where to look for the problem?

Furthermore what are the accepted values of CcdPhysicsEnvironment::setCcdMode ? It seems to have influence but I don't know what values are usefull there.

- Pl?ss Roland
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

It's best to use a fixed timestep, of 60 or 100 hertz. (if necessary, decouple the graphics framerate from physics framerate, using interpolation. Some example/tutorial how to do this would be useful.

Also, your cube is too tiny to be simulated properly with all the default settings. Preferably objects should be at least 0.2 units or bigger. There is a tolerance in place, which is 0.04 units. If your objects is that small, it won't work well.

I would first work on getting the non-ccd version working fine.
The ccd is work in progress/experimental, but it is expected that it will improve support for tiny objects and bigger timesteps. However, variable timestep is not recommended, due to internal caching/warmstarting of the constraint solver.
User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

Post by Dragonlord »

The timestep had been the problem. I used a loop that uses either "defaultTimeStep" or the remaining time if less. This way I ended up with tiny timesteps at some times causing the problem. Carrying over the remaining time and using only the fixed time step solved the problem. The box still bounces a bit on the ground but you really have to get close to see it. Auto-Disabling should fix this I assume.

- Pl?ss Roland
User avatar
SteveBaker
Posts: 127
Joined: Sun Aug 13, 2006 4:41 pm
Location: Cedar Hill, Texas

Post by SteveBaker »

Erwin Coumans wrote:Also, your cube is too tiny to be simulated properly with all the default settings. Preferably objects should be at least 0.2 units or bigger. There is a tolerance in place, which is 0.04 units. If your objects is that small, it won't work well.
I wonder if it would be worth having some kind of external debug setting that would cause the physics module to warn you when your timestep, object size or whatever is in the dangerous range?

This kind of thing is pretty non-intuitive for the physics-naive graphics folk (like me!) - it would be really neat if you could turn on a flag somewhere and have the package check for me that for a gravity value of X and a timestep of Y then an object of size Z or smaller would be bad...or whatever other arbitary limits there are are being stretched. I understand that this may be more 'rule of thumb' stuff - but a warning message from the library would be REALLY handy - even if it's only an advisory....so long as I can turn it off when I know what I'm doing.