Changing postition of a kinematic body and missed collisions

Baxpin
Posts: 5
Joined: Mon Jun 25, 2012 5:18 pm

Changing postition of a kinematic body and missed collisions

Post by Baxpin »

Hi Guys,

I'm new to bullet, so you'll have to pardon me if there's something obvious I'm missing here.

In application I'm developing, I have several rigid kinematic bodies under user control that are rotating and sliding around a fixed area. There's a sphere that the kinematic bodies are supposed to bounce around the screen. This works, and the sphere collides with the kinematic bodies. However, often when the kinematics are sliding or rotating quickly, the sphere will pass through them, so I'm trying to determine what I might be doing wrong that's causing this.

For the kinematic bodies, I have loaded their collision shape as a btConvexTriangleMeshShape. When the object is created, I have set it to kinematic and disabled deactivation. They have a mass and inertia of 0. To change the position/rotation, I get the body's motion state, and call setWorldTransform for the new position. I update the position before I call stepSimulation.

I am updating the position/rotation 30 times/sec. Since the data is coming as user input, it may come in bursts depending on how much they've moved the objects. I am calling stepSimulation, and passing it 64 maxSubsteps and fixedTimeStep of 1/60.0. (I've experimented around with the max substeps, but not seen any real change).

When I draw the object on the screen, I am getting the world transform from the Motion State, and the object is moving smoothly on the rendering, but sometimes a collision is not detected between the sphere and the kinematic bodies.

I think I've provided enough information, but let me know if I've left out a key piece or if more information is needed.
N_K
Posts: 14
Joined: Mon Jun 04, 2012 11:40 pm

Re: Changing postition of a kinematic body and missed collis

Post by N_K »

Although I'm not an expert, but this sounds like you're experiencing tunneling. Have you enabled CCD on all the bodies? See this wiki article for more details.
Baxpin
Posts: 5
Joined: Mon Jun 25, 2012 5:18 pm

Re: Changing postition of a kinematic body and missed collis

Post by Baxpin »

Thanks! I'll give this a try.
Baxpin
Posts: 5
Joined: Mon Jun 25, 2012 5:18 pm

Re: Changing postition of a kinematic body and missed collis

Post by Baxpin »

Ok, I've tried enabling CCD, but I'm not seeing much difference in the results. The interesting thing I've noticed is that even if the sphere is moving very fast, it NEVER passes through any of the objects in the world as long as the kinematic bodies are motionless. However, when the kinematic bodies are rotating or sliding, they can pass through the sphere if they are moving in large steps.

The user input device I'm using sends the change in position from the last packet, so the kinematic bodies do not necessarily move in small steps. Fast movement from the user means larger steps from one spot to the next. My theory on this is that it seems like bullet is treating them as though they are teleporting from A to B, instead of processing it as a movement from A to B. Is there any way I can get Bullet to treat this as a movement from one spot to another?
monkeyman
Posts: 22
Joined: Sat Nov 26, 2011 5:41 pm

Re: Changing postition of a kinematic body and missed collis

Post by monkeyman »

Baxpin wrote: The user input device I'm using sends the change in position from the last packet, so the kinematic bodies do not necessarily move in small steps. Fast movement from the user means larger steps from one spot to the next. My theory on this is that it seems like bullet is treating them as though they are teleporting from A to B, instead of processing it as a movement from A to B. Is there any way I can get Bullet to treat this as a movement from one spot to another?
The thing with kinematic bodies is that you're a bit on your own if you want them to behave like physics-bodies (themselves get pushed by other objects or collide with other objects). Bullet will allow other objects to collide with the kinematics (if enabled) but doesn't really care about the other way.

So your teleportation observation is correct..

You need to manually verify that the space your kinematic object is trying to move through is and will be free of other objects, if you really want to use kinematic objects for this. You can use btCollisionWorld::convexSweepTest for this every time you want to move a kinematic body and only advance it as far as it goes without colliding. It won't catch the case with a very fast-moving sphere, but it sounds like that is not the real problem here.

Be aware that kinematic controlling conceptually is a can of worms, when you fix one problem, you will find the next one, not necessarily due to anything Bullet-specific.

It might be possible in your case to use rigid bodies instead of kinematic objects and let the user input steer them (check for discussions about dynamic character controller here).
Baxpin
Posts: 5
Joined: Mon Jun 25, 2012 5:18 pm

Re: Changing postition of a kinematic body and missed collis

Post by Baxpin »

monkeyman wrote:
Baxpin wrote: The user input device I'm using sends the change in position from the last packet, so the kinematic bodies do not necessarily move in small steps. Fast movement from the user means larger steps from one spot to the next. My theory on this is that it seems like bullet is treating them as though they are teleporting from A to B, instead of processing it as a movement from A to B. Is there any way I can get Bullet to treat this as a movement from one spot to another?
The thing with kinematic bodies is that you're a bit on your own if you want them to behave like physics-bodies (themselves get pushed by other objects or collide with other objects). Bullet will allow other objects to collide with the kinematics (if enabled) but doesn't really care about the other way.

So your teleportation observation is correct..

You need to manually verify that the space your kinematic object is trying to move through is and will be free of other objects, if you really want to use kinematic objects for this. You can use btCollisionWorld::convexSweepTest for this every time you want to move a kinematic body and only advance it as far as it goes without colliding. It won't catch the case with a very fast-moving sphere, but it sounds like that is not the real problem here.

Be aware that kinematic controlling conceptually is a can of worms, when you fix one problem, you will find the next one, not necessarily due to anything Bullet-specific.

It might be possible in your case to use rigid bodies instead of kinematic objects and let the user input steer them (check for discussions about dynamic character controller here).
Thanks for the guidance! I'll give this a look.