Best way to join 2 entities in a odd way?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Best way to join 2 entities in a odd way?

Post by Danthekilla »

Hey everyone.

I have a creature (humanoid) with physics for the body and head (for now) attached to the body and head bone.

The body piece of physics is the actual "body" of the creature and all the rest (head arms etc...) are just sub bodies for fleshing out the collision.

The model is "attached" to the body piece of physics, all other physics are attached to the various bones of the creature.

Now with just the body, the creature can move around and the player can interact with it (push it around etc...) and all is good.

The problem is that when the head physics is attached (which I want the player to be able to collide with) to the bones by setting the physics world matrix each frame the player cannot "push" the creature from the head physics, only by the body physics.

So I have been trying to find a way of attaching the 2 bodys with joints so that if I push the head the body will react. But as the head moves each frame on the animation this has proven to be quite hard.

I tried to adjust the joints each frame so they always tried to keep the head physics where I wanted but I couldn't get anything that looked correct or that was stable...

Any ideas on how I can achieve this? There must be a better way.

Thank!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Best way to join 2 entities in a odd way?

Post by Norbo »

The completely 'proper' method would be to attach everything using joints and constraints, and further, animate all of the physics using motors or an equivalent physical process. By keeping everything physical, collisions would be handled consistently.

The downside being, of course, the extra complexity in setting up all the motors to emulate an animation, and the overly 'physical' appearing result.

An option one step removed from the proper method would be to use a weld between the head and the body. As the animation proceeds, the head would teleport around while the weld's offsets are updated to match the new animated transform (that part is important: the weld must not try to fight against the teleportation!). The usage of teleportation in this method would cause some problems for collision response, but, depending on the animation, these issues may be acceptable.

For example, if the head isn't animating too wildly relative to the body, shoving the head would propagate most of the impulse to the welded parent. If the head's animation is just flailing all over the place, it'll probably seem to miss collisions and respond 'squishily', but the main pushing effect will still get propagated through.

If you wanted to improve the collision response, you could specify the velocities needed to achieve the animation in addition to simply teleporting it. The animated object will still happily go through objects and never fail to achieve the goal animation thanks to the teleportation, but with velocities available, other objects would respond in a more appropriate way. For example, if a character got slapped by the head swinging side to side quickly, it will get knocked back rather than phasing through. And, while it won't be totally correct, some of that 'hit' will propagate back to the rest of the creature's body.
Post Reply