Hi All,
I’m experiencing a really weird problem and I’d appreciate any help, even IDEAS at this point to help me figure it out!
Background
I have a character that is rigged to be a rigidbody corpse as well as a “playable” enemy in the same setup.
As you’d expect, what happens is the rigidbody components and colliders are turned off while its in a “playable” mode, and as soon as it dies, the playable part is turned off, and then the rigid body components and colliders, etc. are turned on via a loop. At that point the game respawns the object ( no instantiation, just the same object is recycled back into the game via a pooling system ).
This all works fine the first 2 - 3 times.
Problem
After the 3rd or so time, a weird problem starts to happen. Every time the rigid body components get re-enabled and the corpse routine kicks in, the joints don’t seem to be working correctly. For example, it looks a little messier and the character starts to progressively look like a blob ( this has to happen around 10 times before it starts to look like that ).
So it appears to me that there is something going wrong with the CharacterJoints possibly? The rigid body and collider seems to be working ok because it will fall and react with the floor, etc., but it seems to be ignoring / messing up the limits imposed by the CharacterJoint components …
Any ideas / suggestions?
Many thanks!
The local positions of bones aren’t guaranteed to be kept correct. The joints will try to hold them together, but they don’t guarantee it - between collision resolution and precision issues, your skeleton will become gradually unstable.
You need to restore the positions somehow when the character is returned to playable mode. You could use components that capture and reapply the localPosition, or you could sample a t-pose animation, or similar.
Hi Superpig,
First off, thanks for the reply, its much appreciated! =)
Does it make any difference that when it returns to “Playable” mode, all the animations are fine? But its like you said, whenever the rigidbodies are re-renabled it seems to progressively degrade with every death … like its “remembering” where it left off or something lol …
Also, I’m using a biped setup, not sure if that changes anything either? lol
Thanks!
Oh, the problem is slightly different to what I thought then.
One thing I’ve found is that you need to be careful about the order in which rigidbodies are activated and deactivated. The rule is: never have an active Rigidbody with a joint that anchors it to an inactive Rigidbody. So in practice, when deactivating the hierarchy you need to make sure you deactivate bottom-up, but when re-activating you need to make sure you activate top-down.
You may also want to clear the velocities of all rigidbodies when you activate them.
Ah, thats interesting!
I’m pretty sure I’m covered on the clearing of velocities, but the order of activating rigid bodies is something I didn’t know!
Ah ok, so maybe the problem is happening when i de-activate the rigidbodies after the first run ( which makes sense, because it works fine the first time round! ). I’ll give that a shot and report back … Fingers crossed! lol
Thanks again for the help, will report back in a bit! =)
Unfortunately it didn’t work …
I tried doing it both ways round lol… I tried reverse when activating, then the other way round, then reverse for both activating and de-activating … Didn’t change anything …
Any other ideas?
Thanks!
Finally got it to work …
For those of you who are having similar problems, I had to build a new class to backup the values of the rigid body / character joint / collider setup of the character at start of frame,
Whenever the character dies and needs to be recreated, you then have to destroy all those components, and dynamically rebuild them from the backup values. It was a bit crazy, but now it seems to be working fine! =)
I Hope this helps others!