Moving platforms

digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Moving platforms

Post by digi12345 »

Hi,

I'm a bit new to bullet physics and I was hoping someone can help me implement a feature in my demo.

I want to create a moving platform that goes back and forth along an axis. The object is a ramp, so it is a irregular mesh meaning the bounding volume is not a box, sphere, cylinder... I've tried the following method with the following results:

- Platform is a kinematic object
- I move it by setting the centre of mass position
- works ok, but...
- problem: the dynamic rigid body object penetrates the kinematic object on the thickest part of the ramp and doesn't really push the dynamic object like you would expect

Is there a better method to make a moving platform that interacts with other dynamic rigid bodies for an irregular mesh? Should it be implemented using a 6DOF constraint and setting a linear velocity? If kinematic object is the way to go, how to I prevent bad penetration with dynamic objects?

Thanks.
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Moving platforms

Post by MaxDZ8 »

That's a bit of a surprise for me. Perhaps generic meshes are supposed to be "empty"?
I'm interested in knowing more as well.

BTW, my 2 cents.

I would, for first, build it from an assembly of simple rigid bodies. Such as boxes. Using a btCompoundShape.

Then, if you look at CharacterDemo and play a bit with it by adding some dynamic rigid bodies you get in the idea that kinematic bodies don't really push things around. They rather just warp to a certain position, compenetrating dynamic objects. The next frame, the compenetrated dynamics will try to recover from penetration. So it looks to me they don't get nearly as much push as they should.

I am currently playing a bit with sweeping ghost objects to provide more push, but that's probably not what you need.

What's the deal with generic meshes? Do you realize the collision algorithm is going to be massively more complicated?
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Moving platforms

Post by MaxDZ8 »

digi,
while searching for a thing I'm interested in, I found this
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=6902&

I guess that's your problem?
digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Re: Moving platforms

Post by digi12345 »

Thanks for your reply. I don't really need generic meshes, but I'm trying to experiment the possibilities of what I can do. Obviously creating triangle mesh bounding volumes are more complicated and processor intensive but it's nice to know I have that option if it came down to it.

However, after an hour of experimenting I managed to recreate what I wanted using gimpactmesh for my moving platform and I attached it to a static body using a 6dof constraint and limiting the axis and angle to the direction I want it to move. Then I give my platform a linear velocity. A bit more work than moving a kinematic object but it interacts with other dynamic objects without penetration.
User avatar
Pyritie
Posts: 25
Joined: Thu Aug 11, 2011 6:42 pm

Re: Moving platforms

Post by Pyritie »

digi12345 wrote:Hi,Is there a better method to make a moving platform that interacts with other dynamic rigid bodies for an irregular mesh? Should it be implemented using a 6DOF constraint and setting a linear velocity? If kinematic object is the way to go, how to I prevent bad penetration with dynamic objects?
couldn't you just change the translation part of the body's transform?
digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Re: Moving platforms

Post by digi12345 »

Do you mean update the transform of the kinematic moving platform? I can but it doesn't seem to interact with dynamic objects that well. I would get unwanted penetration between the kinetic object and dynamic object.
rbgrn
Posts: 12
Joined: Wed Aug 24, 2011 6:16 am

Re: Moving platforms

Post by rbgrn »

I just did this. Here's how it works - make sure that:

Platform has no mass. It needs to be static.
Platform has the CF_KINEMATIC_OBJECT flag set.
When you set the position of the platform to move it, you need to set that position both on the btBody's world transform as well as the motionstate. If you don't set it on the motionstate, it won't be simulated properly.

btTransform trans = btBody->getWorldTransform();
trans.setOrigin(btVector3(pos.x, pos.y, pos.z));
myBody->setWorldTransform(trans);
myMotionState->getWorldTransform(trans);
trans.setOrigin(btVector3(pos.x, pos.y, pos.z));
myMotionState->setWorldTransform(trans);
User avatar
Pyritie
Posts: 25
Joined: Thu Aug 11, 2011 6:42 pm

Re: Moving platforms

Post by Pyritie »

digi12345 wrote:Do you mean update the transform of the kinematic moving platform? I can but it doesn't seem to interact with dynamic objects that well. I would get unwanted penetration between the kinetic object and dynamic object.
Yeah but then the dynamic objects would just get out of the way, as usual. Things penetrating each other is kinda an essential part of physics engines :P
rbgrn
Posts: 12
Joined: Wed Aug 24, 2011 6:16 am

Re: Moving platforms

Post by rbgrn »

Pyritie wrote:
digi12345 wrote:Do you mean update the transform of the kinematic moving platform? I can but it doesn't seem to interact with dynamic objects that well. I would get unwanted penetration between the kinetic object and dynamic object.
Yeah but then the dynamic objects would just get out of the way, as usual. Things penetrating each other is kinda an essential part of physics engines :P
I think he's talking about some unwanted behavior that I witnessed when I failed to update the position of the motionstate on the kinematic object after assigning it the kinematic flag. Yes, normally you do want normal slight penetration with a solution but what I saw was abnormal and inconsistent before I figured out to use the motionstate in conjunction with the rigid body's world transform.
digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Re: Moving platforms

Post by digi12345 »

From what I recall, if you set the position transform of a kinematic object, the object basically teleports through space. If the ramp kinematic object is moving in one direction and the dynamic object is moving in the opposite direction and it pushes enough it will have deep penetration (usually through the thickest part) in the ramp and eventually go right through it. Is this expected behavior? I'm trying to make sure no matter how much force (within reason) the dynamic object does not go through the kinematic object. Sure, slight penetration between objects is ok, but having the object go right though another object is not what I'm looking for.
rbgrn
Posts: 12
Joined: Wed Aug 24, 2011 6:16 am

Re: Moving platforms

Post by rbgrn »

digi12345 wrote:From what I recall, if you set the position transform of a kinematic object, the object basically teleports through space. If the ramp kinematic object is moving in one direction and the dynamic object is moving in the opposite direction and it pushes enough it will have deep penetration (usually through the thickest part) in the ramp and eventually go right through it. Is this expected behavior? I'm trying to make sure no matter how much force (within reason) the dynamic object does not go through the kinematic object. Sure, slight penetration between objects is ok, but having the object go right though another object is not what I'm looking for.
Did you try what I posted? Erwin gave that exact bit as a kinematic demo and it worked correctly for me in every direction with a dynamic object sitting on top of the kinematic platform (the object moved with the platform as expected) in 2.78.
digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Re: Moving platforms

Post by digi12345 »

Right I haven't tried it yet, as I'm refactoring my codebase at the moment. Ah yes, sitting on top of the dynamic object is fine, what I'm saying is if the dynamic object is on the same level as the ramp and collides with the thickest part of the ramp.

For example, a dynamic sphere rolling left against a ramp moving right. Both are on the same level and the sphere is pushing against the thickest part of the ramp. What happens is that the ramp (static, kinematic) pushes the sphere then the sphere will penetration half way, then appears on the other side. the sphere doesn't get pushed off to the right. It's even worst if you have control over the sphere and you start pushing against the ramp with a user added force.

Note, if the ramp is moving slow enough, everything seems fine until you start having the sphere push hard against the ramp.
rbgrn
Posts: 12
Joined: Wed Aug 24, 2011 6:16 am

Re: Moving platforms

Post by rbgrn »

digi12345 wrote:Right I haven't tried it yet, as I'm refactoring my codebase at the moment. Ah yes, sitting on top of the dynamic object is fine, what I'm saying is if the dynamic object is on the same level as the ramp and collides with the thickest part of the ramp.

For example, a dynamic sphere rolling left against a ramp moving right. Both are on the same level and the sphere is pushing against the thickest part of the ramp. What happens is that the ramp (static, kinematic) pushes the sphere then the sphere will penetration half way, then appears on the other side. the sphere doesn't get pushed off to the right. It's even worst if you have control over the sphere and you start pushing against the ramp with a user added force.

Note, if the ramp is moving slow enough, everything seems fine until you start having the sphere push hard against the ramp.
I think you misunderstood me. I'm talking about the kinematic object pushing dynamic objects and dynamic objects resting on top of the kinematic, not the other way around. I just had the issue you're having and fixed it by setting the motionstate.

Watch the last minute of this video, it uses the code I keep telling you to try :)

http://www.youtube.com/watch?v=y4OsSTlANdM
digi12345
Posts: 13
Joined: Mon Aug 15, 2011 5:43 pm

Re: Moving platforms

Post by digi12345 »

I just tried your code. Here is what I get: http://www.youtube.com/watch?v=e4HlLWtDjak
Is this expected?
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Moving platforms

Post by MaxDZ8 »

digi12345 wrote:I just tried your code. Here is what I get: http://www.youtube.com/watch?v=e4HlLWtDjak
Is this expected?
I had exactly the same problem! Can you check your setActivationState calls? I pulled my hair off for a day then I figured out that I wrote (slip error)
setActivationState(0)
instead of
setActivationState(DISABLE_DEACTIVATION)

As soon as I realized that, everything went ok.
Post Reply