Animation and Physics

Julian Spillane
Posts: 9
Joined: Tue Aug 12, 2008 9:15 pm

Animation and Physics

Post by Julian Spillane »

Hey all,

We've integrated Bullet into our Wii game, and everything has been running very smoothly (thanks to everyone who's contributed to make a great open source API).

We've run into what's more of a logical problem for the behaviour of our enemies. We have access to animation keyframe data, and we want to be able to move the physics meshes along with the model's animation. The only thing we can't work out, is how can we transform the physics mesh along these animations while still retaining the benefits of physical simulation (i.e., if I'm explicitly setting positions of the rigid body to the keyframe positions, it'll counteract any velocities currently applied to the object).

There's probably a simple solution to this, I just might not be looking at it at the right angle.

Thanks in advance!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Animation and Physics

Post by Erwin Coumans »

Julian Spillane wrote: We've integrated Bullet into our Wii game, and everything has been running very smoothly (thanks to everyone who's contributed to make a great open source API).

We've run into what's more of a logical problem for the behaviour of our enemies. We have access to animation keyframe data, and we want to be able to move the physics meshes along with the model's animation. The only thing we can't work out, is how can we transform the physics mesh along these animations while still retaining the benefits of physical simulation (i.e., if I'm explicitly setting positions of the rigid body to the keyframe positions, it'll counteract any velocities currently applied to the object).

There's probably a simple solution to this, I just might not be looking at it at the right angle.
There are companies making money in this area of physics based animation (Natural Motion), and there is plenty of research in this area. So don't expect a single simple solution, there are probably many, and each will have some PROs and CONs. Some 'simple' ways are using dynamics rigid bodies, and apply impulses to keep them in the right location. Another way is to use kinematic objects.

What kind of effect/interactions do you want to achieve with those 'physics' meshes?
Thanks,
Erwin
Julian Spillane
Posts: 9
Joined: Tue Aug 12, 2008 9:15 pm

Re: Animation and Physics

Post by Julian Spillane »

Hi Erwin,

Thanks for the reply. I totally didn't mean to trivialize the problem (I'm totally aware of the research going on and products like Natural Motion, etc.). My problem is nowhere near complex, and I will demonstrate with an example:

One of our enemies is effectively a sphere (for the problem's sake). He moves by bouncing. We were going to simulate the bounce using impulses/velocities, but our animators wanted more control to get that "cartoony" feel. We want to be able to detect collisions during the course of this animation, but if we're not updating the rigid body's position, then his box will stay at the root while the model animates.

i.e.

Image

Our body is being simulated (by gravity, collisions with world, etc.), but we want to be able to move the mesh along with the animation. One thought was to calculate the velocity of the animation between frames and add that to the body's current velocity, but I haven't attempted it yet.

I hope this makes things a bit more clear! We're definitely not trying to outdo Natural Motion. ;)
AxeD
Posts: 36
Joined: Tue Jun 17, 2008 8:28 pm

Re: Animation and Physics

Post by AxeD »

Hi,
You should do few things:
1. Avoid copying from Gfx to Physics.
2. Use forces, translation, rotation, and all velocities modification.
3. You can use object animation without rigidbody modification.

I have tested that on Wii.

Best regards
Julian Spillane
Posts: 9
Joined: Tue Aug 12, 2008 9:15 pm

Re: Animation and Physics

Post by Julian Spillane »

Thanks for the reply, although I'm not exactly sure what you mean...
1. Avoid copying from Gfx to Physics.
So you're saying I shouldn't force the physics mesh to follow the animation explicitly, yes?
Use forces, translation, rotation, and all velocities modification.
Do you mean I should extract the translational and rotational information from the animation and "recreate" it as forces?
Sorry for the confusion, I'm just not sure exactly what you mean.

Thank you very much though!
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Animation and Physics

Post by sparkprime »

My 2c:

First cent:

If you do force the positions, there are at least 2 problems you may run into:

Destabilising joints - unless you move all the rigid bodies appropriately but even then keep an eye out for problems

Contacts - i think you may end up with weird contacts persisting into the new locations? Something to look out for anyway.

If you remove all the bodies/hinges and put them back in again (no need to destroy/recreate them, you should not run into these problems.

Second cent:

However you are still moving things around at a fairly course granularity, assuming there are more internal physics steps than graphical frames. You would get smoother collisions by changing the position every internal tick using the callback, or by writing your own stepSimulation loop. Cent 1 probably still applies though.

I believe you can set the velocity to whatever you want per internal step however it will get changed a lot before it's used to change the position. I urge you to look at the code;

http://www.continuousphysics.com/Bullet ... 95373dc797

One step at a time: The forces will be integrated into the velocity left over (or modified by you) from the previous frame, damping applied, and then the resultant velocity will be integrated into a new position in the call "predictUnconstraintMotion". However this is not the final position - collision detection is performed which further tweaks the velocity, and also hinge constraints have an influence. Finally this resultant velocity is used to compute the new position at "integrateTransforms" (the position computed by "predictUnconstraintMotion" is discarded).

With this info you might be able to think more clearly about how and where to combine the collision/constraint-driven motion with your procedural motion. Or at least ask further questions :)

It seems you need to work out when the top and bottom of the bounce are - somehow, maybe you can use a collision callback to find out when it hits the ground and then add to this or use a ray to find out when you're at the top of the bounce. Then you can tweak velocities at the right time to get the effect you want. You may want to overide or disable the impulses that are caused by the ground collision for instance, or override gravity. See what you think and I imagine you'll have to experiment a lot to get the effect you want because realism has gone out the window :)