"Bouncy" Elevators

tinto
Posts: 2
Joined: Fri May 29, 2009 6:35 pm

"Bouncy" Elevators

Post by tinto »

Hi,

I have an odd situation in an App I am writing and was hoping someone could help out. I have a sphere that is resting on a platform that can move up and down (the 'elevator'). Initially the platform is stationary and the sphere rests fine. I then start moving the platform up, and would expect to see the sphere move up with it, but instead it bounces it up into the air. The platform continues to move up and when the sphere lands back on it, it again is bounced up into the air (kinda makes sense the second time, but the first time is the problem). The platform is moving slow enough that I wouldn't expect this to happen.

The sphere is created as a btSphereShape with mass of 1. The platform is a btBvhTriangleMeshShape, which is set to be kinematic and has a mass of 0.

platform_body->setCollisionFlags(platform_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
platform_body->setActivationState(DISABLE_DEACTIVATION);

When I move the platform up, I do it via the setWorldTransform method.

Does anyone know what would cause this? Is there some other, better, way to handle this type of scenario? Any help would be greatly appreciated.

Thanks!
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: "Bouncy" Elevators

Post by ola »

Sounds like you get some penetration between the sphere and platform initially before their speeds match. If you know the sphere is resting on the platform, try setting it's linear velocity to the same as the platform when starting to move the platform.

Alternatively, maybe you can try to slowly ramp up the platform speed instead of suddenly giving it some constant velocity.

For kinematic objects I've also found that it helps setting the linear velocity (even though they are not simulated physically) -- it influences the friction.
tinto
Posts: 2
Joined: Fri May 29, 2009 6:35 pm

Re: "Bouncy" Elevators

Post by tinto »

I did try setting the linear velocity of the platform, and also slowly ramping up the speed of it, but neither made any difference. Slowly ramping up the speed wouldn't really be feasible in the application anyway, as the platforms would be animated in a 3D package and their positions updated from that animation data. Requiring the artists to slowly ramp up each movement wouldn't really be a feasible option (manually). I guess if there's no other option, then it might be feasible to somehow enforce it in code.

As for setting the sphere's velocity - I haven't tried that yet and will try it now to see if it makes any difference. Although... wouldn't this end up giving very odd visual results? Say the sphere bounced onto the platform from an angle just as the platform started to move - if I set it to the linear velocity of the platform it would seem to "snap" upwards rather than follow its natural path. I guess I could ensure its current linear velocity is below some kind of threshold before doing this - but it all sounds like I'm starting to tread into the waters of special cases and hard-coded magic numbers... Or maybe instead of setting it to the linear velocity of the platform, I need to add the linear velocity to the sphere's current linear velocity.

I had assumed I was just doing something wrong. Has anyone else run into this problem and come up with their own workarounds? Is there an "official" way to do this?