having issues with two objects "sticking together"

User avatar
detox
Posts: 12
Joined: Wed Nov 22, 2006 6:52 pm
Location: Ohio, USA

having issues with two objects "sticking together"

Post by detox »

Hi,

I have a simple character controller which uses a full dynamics body and a sphere collision shape. I set velocities using setLinearVelocity() to move it around based on user input. I also have a jump function which uses applyCentralImpulse(). It's very similar to the Bullet character control demo class. I also cast a ray downwards to check if the player is currently sitting on something.

I've started to add moving platforms and attaching the player to moving platforms by checking through all the collisions for a match between the player and any of the moving platforms. If there is a collision I add the moving platform's velocity to the player's velocity to keep them "attached".

I've tried both dynamic body moving platforms, controlling them much like the player, by setting velocities. I've also tried kinematic moving platforms, and directly set the platforms position.

The issue I am having is that once the player has been sitting on a moving platform for a couple seconds they seem to get somewhat stuck. For instance, trying to jump off will take multiple applications of applyCentralImpulse() to get them to move upwards. There is also a delay moving left/right/back/forward, but continuous application eventually moves the player.

I can eliminate the issue by setting the gravity of the player rigid body to 0 when it is attached, and then reseting back to (0,0,-10) [z-axis is up-down in my coord.sys] However doing this causes many other issues as you might imagine.

This "sticky" issue does not happen when moving the player on static collision shapes, or on fully dynamic rigid bodies, fully controlled by Bullet (no set velocities). It only happens when the player rests on kinematic or dynamic bodies which I modify either velocity or position respectively.

I have of course turned off auto-sleeping on all moving platforms and the player. I am using default collision margins, default friction, and am stepping the world using something like stepWorld( delta_ms, 1 ).

Has anyone had similar issues?

Should I be using some other strategy for player<->platform attachment? Making/breaking a constraint?

Thank you for any help!
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: having issues with two objects "sticking together"

Post by ola »

I don't know what actually causes your "sticking" problem, but here's how I've done my character controller. Maybe you'll get some inspiration from it..

I use a capsule shaped rigidbody (fully dynamic, disabled deactivation, restitution zero), but a sphere would do the same trick.

I cast a ray downwards to see if the character is standing on something. If it's standing on something, I can see the velocity in the point where the raycast hit, of the thing the character is standing on. Mostly it's the static environment (and the velocity is zero), but it can also be a platform or something else, which is moving.

To move my character, i apply impulses on the character body correct the character velocity to the target velocity (for walking, running, etc). I do this for each internal timestep that Bullet does. The velocity is measured relative to the object it is standing on.

This way, the character can stand on anything that is moving, and will stay there. And I do not have to define what's a platform and what is static, it just works.

I've also defined a maximum impulse that can be applied. This makes it more difficult for the character to climb very steep hills (gets slower and slower the steeper it is). Also makes it possible to push the character around when it's hit by an object that is supposed to be stronger than the character. Jumps can be done by applying an upward impulse, like in your case.

Best regards,
Ola
User avatar
detox
Posts: 12
Joined: Wed Nov 22, 2006 6:52 pm
Location: Ohio, USA

Re: having issues with two objects "sticking together"

Post by detox »

That was very helpful. I will try implementing your method of moving the character with whatever it's standing on in my character controller. It sounds much simpler than what I am doing currently. I will try using impulses too instead of directly setting velocities.

Did you modify the Bullet timer system to call a function to update your character with impulses every Bullet internal timestep?

Thank you


EDIT:

I looked through the API doc and just now saw the callback for the world step.

I'm using a downward raycast as you described to check for objects below the player and their velocities - I'm using btCollisionWorld::ClosestRayResultCallback and it seems to work pretty well so far. I haven't had a chance to test for the "sticky" issue yet though. If I still have it I'll isolate the problem and post a piece of demo code.

Thanks again for your help
Mowan259
Posts: 5
Joined: Sat Jun 21, 2008 8:42 am

Re: having issues with two objects "sticking together"

Post by Mowan259 »

Sorry for necroing this thread, but I thought I'd contribute here since the original problem was never formally resolved.

We were having the same issue with our title, where if the character was at rest on another body for a short period of time and the user pressed the "jump" button, the character would jump at varying heights. I checked the CharacterDemo sample to see if perhaps I was missing something, but that sample exhibits the same problem. Unfortunately, non-deterministic jump heights are completely unacceptable for the type of game we are developing.

I had the same suspicion that the problem was related to friction accumulation/weirdness or something, because I noticed that the problem only happened when jumping while standing still. If I jumped while moving, everything worked fine.

The solution for us (or perhaps "workaround" is a better term) was to reset the linear velocity in the InternalTickCallback. In other words:

1. User presses the jump button
2. Call setLinearVelocity() with the desired jump velocity, and set a jump boolean to true
3. Step the physics simulation
4. InternalTickCallback gets triggered. If jump boolean is true, call setLinearVelocity() again with the same jump velocity, and clear the jump bool

I haven't tested this using the applyForce()/etc. methods, but I expect it to work as well as the problem seems to be isolated to that very first frame.

Hope this helps.
Julian Spillane
Posts: 9
Joined: Tue Aug 12, 2008 9:15 pm

Re: having issues with two objects "sticking together"

Post by Julian Spillane »

Sorry to necro this thread even more, but we're having the exact same problem and Mowan's solution of using the InternalTickCallback to reset the velocity isn't working for us.

Basically, what we're finding is that our jumps are generally deterministic, but after an indeterminate number of jumps, our player suddenly skyrockets upwards and I can't seem to figure out what's going on.

Does anyone out there have any ideas?

Thanks a lot!