Rigid Body sliding off moving kinematic platform (vsync off)

User avatar
Hydrocity
Posts: 2
Joined: Sun Nov 18, 2012 11:55 pm

Rigid Body sliding off moving kinematic platform (vsync off)

Post by Hydrocity »

I have implemented my own character controller using a capsule rigid body and setLinearVelocity() to move it and applyCentralImpulse() to jump. That's working fine, as well as the collision world. I recently added a moving platform(moving back and forth between two points) that is represented by a rigid body as well, except it's kinematic. It is moved each frame by my animator (using the Ogre3D rendering engine) and it is updated like so:

Code: Select all

   btTransform trans = m_rigidBody->getWorldTransform();
	trans.setOrigin(btVector3(pos.x, pos.y, pos.z));
	m_rigidBody->setWorldTransform(trans);
	btMotionState* motion = m_rigidBody->getMotionState();
	motion->getWorldTransform(trans);
	trans.setOrigin(btVector3(pos.x, pos.y, pos.z));
	motion->setWorldTransform(trans);
The issue is that when I jump on top of the platform, I can stay on for a bit, but I begin sliding off. This only happens when vsync is disabled, so the frame rate varies from about 270-320. However when vsync is enabled, I can sit on the platform perfectly and not slide, due to the frame rate being locked at 60. I'm not sure why this happens. I've been doing some research on this forum and found some information about kinematic bodies and supposedly how they are not interpolated by Bullet. I'm very new to physics engines so my knowledge on this sort of thing is limited.

My physics world is updated like so:

Code: Select all

m_btWorld->stepSimulation(timeSinceLastFrame * 0.015f, 60);
I've read quite a bit about how this function causes trouble for people, and I've tried changing the maxSubSteps to zero, which helps with the sliding a little, but it still will eventually slide off with vsync disabled, and with it enabled, the rigid body bounces at a constant interval.

I also tried setting some interpolation info, however this just makes it seem as if the platform has no friction at all, and it just slides under me.

Code: Select all

   m_rigidBody->setInterpolationWorldTransform(m_rigidBody->getWorldTransform());
	m_rigidBody->setInterpolationLinearVelocity(btVector3(0, 0, 0)); // not sure if this would be correct
	m_rigidBody->setInterpolationAngularVelocity(btVector3(0, 0, 0));
Also, the friction of both bodies is 1.0. I can increase the friction and the sliding is reduced, however the player can no longer walk on the platform.

So, given this information, I believe it has something to do with the time step each frame. Everything I try doesn't seem to fix the issue. I can provide a video if needed. Should I be updating the kinematic body separately? Any insight on this issue would be invaluable.
Empire-Phoenix
Posts: 24
Joined: Sat Nov 07, 2009 7:57 pm

Re: Rigid Body sliding off moving kinematic platform (vsync

Post by Empire-Phoenix »

A probably working hack would be to determine wich impulse your player needs to move with the platform, then when it is standing on one (raycast downwards) apply this to the player. set the platforms friction to 0.
User avatar
Hydrocity
Posts: 2
Joined: Sun Nov 18, 2012 11:55 pm

Re: Rigid Body sliding off moving kinematic platform (vsync

Post by Hydrocity »

Indeed, it is a hack but it works. It still looks sloppy on higher frame rates but the sliding is reduced to almost nothing, which is fine for my case. Thanks.