- Home /
Problems with ragdolls and no gravity
In the game I'm working on, movement switches between gravity and no gravity (3D). I had it working with my enemies in that they would move properly on the ground, transition to no gravity movement, fall back to the ground when gravity came back on etc. However, I ran into an issue where when enemy bodies that were floating around in no gravity fell back to the ground, they would land in unnatural ways (such as landing on their head upright and remain upright) because they just had body sized collision (so they were just boxes as far as the physics system was concerned). But then the creator of the enemy model asset I was using released a ragdoll version of the enemy, so I decided to swap it out. Here is where I run into issues. I'm doing basically the same thing I was before, plus the additions I figured I needed based on online reading:
I keep a reference to the RigidBody on the character, as well as an array of the RigidBodies on the joints.
I set isKinematic property of the top level RigidBody and the joint RigidBodies to true at the start (for animations and movement).
I set the useGravity property of all the RigidBodies to true or false depending on the state of the game.
When the enemy dies the death animation plays, and after the death animation I set the isKinematic property of all the RigidBodies to false and disable the animator component to enabled the ragdoll functionality.
However, while the enemy still functions properly on the ground, it is now incapable of leaving the ground when gravity it turned off. Additionally, when the ragdoll is activated after death, it behaves very unnaturally. It slowly floats around in the air (regardless of the gravity setting), twitching and spasming until it happens to hit a surface (wall, ceiling, whatever) at which point it launches off like it was shot out of a cannon, completely blasting through any surface it hits next into nothingness. I've even seen the model mesh stretch and glitch out when this happens. Any idea what is going on here, and what I might be missing?
For reference, this is my code that enables or disables gravity on the ragdoll (the kinematic code is basically the same, only with the isKinematic property instead).
private void SetRagdollGravity(bool gravityOn)
{
rigidBody.useGravity = gravityOn;
foreach (Rigidbody ragdollPoint in ragdollPoints)
{
ragdollPoint.useGravity = gravityOn;
}
}
I've looked through the hierarchy and confirmed that it doesn't miss any RigidBodies and that it is setting things as I would expect.
Your answer
Follow this Question
Related Questions
Tracking Force Added to Kinematic Rigidbody 2 Answers
How can I make character become a ragdoll with isKinematic? 1 Answer
Disable ragdoll without changing Kinematic boolean? 2 Answers
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
Moving a regular Unity primitive and PhysX performance 0 Answers