Page 1 of 1

Need to move kinematic bodies and get good dynamic collision

Posted: Thu Jan 13, 2011 2:14 am
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.

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

Posted: Thu Jan 13, 2011 2:25 am
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).

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

Posted: Thu Jan 13, 2011 2:56 am
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.

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

Posted: Thu Jan 13, 2011 2:57 am
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.

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

Posted: Thu Jan 13, 2011 12:53 pm
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.

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

Posted: Sat Jan 15, 2011 6:32 pm
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?

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

Posted: Sat Jan 15, 2011 7:16 pm
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.

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

Posted: Sat Jan 15, 2011 7:20 pm
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.