Need to move kinematic bodies and get good dynamic collision

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Need to move kinematic bodies and get good dynamic collision

Post by BrianL »

Is it possible to do this? I need to procedurally reposition (up and down) some kinematic bodies every frame. I have some dynamic entities sitting on top of the procedurally moving kinematic entities. Is it possible to have the dynamic entities properly interact with the kinematic entities in this case?

Currently, the dynamic entities fall and stop on top of the kinematic entities. However, anytime the kinematic entities move upward from that point, the dynamic ones don't seem to respond very well and major inter-penetration occurs. Sometimes, the dynamic entities will eventually work their way through the kinematic entities and fall completely out of the world.

Any tips, ideas, or suggestions? Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Need to move kinematic bodies and get good dynamic colli

Post by Norbo »

That tends to happen when entities are teleported (setting their position directly, or equivalently using the Teleport methods). During teleportation, the entity's velocity remains unchanged. Since only the position changes, the constraint solver only sees changed penetration depth and attempts to gently correct it. This can act like a very 'squishy' form of collision response.

The fix is to control motion using velocity. If you need to move up 1 unit in 1 frame at 60hz, you'd have an upward velocity of 60 units/second. For convenience, the engine has some built in 'path following' features. The EntityMover class can control the linear motion of any entity according to some goal (similarly, EntityRotator handles angular motion).
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Need to move kinematic bodies and get good dynamic colli

Post by BrianL »

Norbo wrote:The fix is to control motion using velocity. If you need to move up 1 unit in 1 frame at 60hz, you'd have an upward velocity of 60 units/second.
So you think directly setting the Entity's LinearVelocity would solve the problem then? If so, I'll try that first thing tomorrow. Thanks for the quick reply.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Need to move kinematic bodies and get good dynamic colli

Post by Norbo »

Yup, if it was previously being controlled using position/teleportation, using velocities directly should solve it. Be careful about the buffered properties though- you may want to go ahead and use the InternalLinearVelocity property to avoid confusion (the buffered properties are going to be stuck in a more reasonable location in v0.15.0). Or just use the EntityMover, depending on what feels easier.
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Need to move kinematic bodies and get good dynamic colli

Post by BrianL »

Norbo wrote:The fix is to control motion using velocity. If you need to move up 1 unit in 1 frame at 60hz, you'd have an upward velocity of 60 units/second.
I implemented this fix this morning and it works perfectly. Thanks again.
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Need to move kinematic bodies and get good dynamic colli

Post by BrianL »

My timing efforts indicate that the Space.Update() call using this method of updating 1024 kinematic entities once per frame is taking around 10 ms on the 360. I'm using a DynamicBinaryHierarchy. Does that sound high, low, or about right?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Need to move kinematic bodies and get good dynamic colli

Post by Norbo »

That's about right. The Xbox360 isn't exactly a speed demon with XNA :)

You might be able to get another tiny jump in performance (a millisecond maybe, depending on where the time is being spent) by multithreading the velocity controls. If you're using the EntityMover, try setting its IsUpdatedSequentially to false. It defaults to true for simplicity, but it should work just fine updating in parallel too since it only works on a single entity. If it's not using EntityMover, you might be able to still multithread it pretty easily by using the ThreadManager's for loop method.

If the boxes are very tightly packed together, try giving them a little breathing room. Ensure the AABB's don't overlap between adjacent boxes. They don't create collision pairs and the early out test is very fast, but doing thousands of fast early out tests can still have some effect (perhaps a couple of milliseconds).

There might be some other tricky things you can do, like removing objects from the broadphase. This would make the management of things colliding with the boxfield difficult, with questionable performance benefit.
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Need to move kinematic bodies and get good dynamic colli

Post by BrianL »

Sounds good then. I'll try a few of the suggestions that I haven't already tried. Mostly I just wanted a quick sanity check. Thanks.
Post Reply