Big problem with kinematic-dynamic constraints

Post Reply
Lwmte
Posts: 4
Joined: Sun Feb 24, 2013 3:42 pm
Contact:

Big problem with kinematic-dynamic constraints

Post by Lwmte »

Currently I am trying to implement Lara's braid hair in our OpenTomb project, and I have faced serious problem with "stiffness" or "hardness" of constraint which connects braid to character's head.

The setup is: Lara's head is a kinematic rigid body (zero mass, CF_KINEMATIC_OBJECT flag is set) which gets its movement from predefined animations and general GL-like entity's transformation matrix (to move Lara around). Braid is a chain of dynamic rigid bodies (triangle mesh shapes or capsules) connected with cone twist or generic 6DOF constraints.

The problem is, when Lara moves (especially running, jumping, or any other fast movement), hair gets "disconnected" from her hair, as if head-hair constraint is stretched or reacts with a big delay. Here is extreme case of this issue.

As I have scanned whole Bullet forum for possible solutions of this problem, which seems quite common, I already tried all the solutions I found, namely:

1. Set 10 or 100 times larger mass in calculateLocalInertia for hair collision shapes.
2. Set damping for hair bodies to (0.01, 0.01) - which I really hate, cause low damping values result in "wrong" inertia.
3. Make Lara's head body static instead of kinematic (CF_STATIC_OBJECT flag).
4. Forcing Lara's head body activation state (DISABLE_DEACTIVATION) - but with it, head-hair constraint becomes inactive at all!
4. Set joint parameter BT_CONSTRAINT_STOP_CFM to minimum (0.00001).
5. Set joint parameter BT_CONSTRAINT_STOP_ERP to maximum (0.8, larger values produce bugs).
6. Increasing solver iterations to 100, 1000, etc. (with larger values, I get MAJOR slowdowns).
7. Forcing fixedTimeStep to 1./1000. (which generally breaks other physics in engine).

With the help of all aforementioned solutions, I got better results, but still - I just can't get a hard connection between head and first hair body! Here is the demo of current version.

So, is it possible just to make a HARD link between head and hair, as it was done in original games?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Big problem with kinematic-dynamic constraints

Post by drleviathan »

Yes, one way to do what you want: perform a manual verlet relaxation of point-to-point constraints after each call stepSimulation().
Lwmte
Posts: 4
Joined: Sun Feb 24, 2013 3:42 pm
Contact:

Re: Big problem with kinematic-dynamic constraints

Post by Lwmte »

I'm not into math (actually really bad), but quick search tells me it's some complicated algorithm... If so, I'm afraid I won't be able to implement it properly. I hoped I can use already existing Bullet functionality for that! :)

I just tried one more method - calculate current speed of kinematic body deriving it from transformation matrix and then apply it via setLinearVelocity. It doesn't help, but at least hair movement is now much more realistic.

So basically, there is no easy way in Bullet to create stiff link between kinematic/dynamic bodies? Like, maybe, modifying some parameters of constraint or rigid body?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Big problem with kinematic-dynamic constraints

Post by Erwin Coumans »

Lwmte wrote: So, is it possible just to make a HARD link between head and hair, as it was done in original games?
The game character has likely huge changes in velocity, causing issues if you don't compensate for it.

A common solution is to mix local and global velocities for the hair, cloth and connected constrained rigid bodies. There is a recent article that explains the idea of mixing local and global velocities more in details, see also the comments: http://www.gamasutra.com/view/feature/1 ... on_in_.php

We should add some example in the example browser, because it is a common problem. If you case, please report a request in the github tracker at http://github.com/bulletphysics/bullet3
So basically, there is no easy way in Bullet to create stiff link between kinematic/dynamic bodies? Like, maybe, modifying some parameters of constraint or rigid body?
Yes there is: you can use a btMultiBody, but you will still suffer from the unrealistic large changes in velocities so it won't help you much. It is recommended to 'manually' transfer a part of the linear and angular velocities from the kinematic bodies to the dynamic ones.

Thanks and good luck!
Lwmte
Posts: 4
Joined: Sun Feb 24, 2013 3:42 pm
Contact:

Re: Big problem with kinematic-dynamic constraints

Post by Lwmte »

Yes, there are lots of rough transitions between different animations (original Tomb Raiders also suffered from this problem). Actually, I checked original TR4 and TR5 games, and seems they also suffering from braid misalignment on fast moves. Strangely, in TR2 and TR3, hair behaves much more stable (maybe because they didn't use skinned hair at that time).

I did what you suggested - mixed up local headmesh and global entity velocities, and indeed, it helped a lot! For some reason, I also needed to multiply mixed velocity by 50 (!) to achieve decent result. Probably I did something wrong, because I'm really bad at math! :mrgreen:

Here is the current result. Don't take in mind wrong hair offset and hole in the head, that's because there is no skinning yet.

Unfortunately, there is another issue I'm fighting right now - constraints become "shaky" on fast movement, and it's not caused by low ERP values... I guess, something may be wrong in engine itself, because when I turn vsync on (hence, rendering speed becomes the same as physics), shaking is gone.

Yes, example code will be great! I'm sure MANY people need to solve similar problem!

Thank you very much for your answer!
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Big problem with kinematic-dynamic constraints

Post by Flix »

First of all: I've never tried using constraints between kinematic and dynamic bodies.

Anyway in the past I've successfully "chained" dynamic rigid bodies solving the problem of occasional "gaps" between them simply by "faking" the graphics.

This is easier to do if your hair braid is made by a strip of quads that look at the camera (billboard strip): you can regenerate it every frame based on the current transforms of the bodies.

(Here is an old video of a crane-truck-chain I made using this method: https://www.youtube.com/watch?v=7Oe4DkI6dYY. As you can see the drawback is that the chain looks a bit too "elastic").

However, as I've said, this does not solve the problem between kinematic-dynamic constraints, it can only help to hide it if you're using a billboard chain :? .
Post Reply