I'm making a multiplayer game, and I want to add ragdoll physics to player when the player dies. But when I activate the ragdoll physics (rigidbodies) the player just flys to the moon XD I am using ragdoll first time and I don't know how to fix this issue.
#Problem with Ragdoll
1 messages Β· Page 1 of 1 (latest)
Do you apply a force to all rigidbodies when you activate it? or just the Hips rigidbody? Also if you have a collider on your parent gameObject (Player Parent) like a capsule collider, are you disabling this before enabling the ragdoll?
No I am not applying a force at all. And yes I am disabling the character controller (capsule collider) before enabling ragdoll colliders.
public void ToggleRagdoll(bool toggle) {
_rig.SetActive(!toggle);
_animator.enabled = !toggle;
_controller.enabled = !toggle;
_pelvisCollider.enabled = toggle;
_spineCollider.enabled = toggle;
_headCollider.enabled = toggle;
foreach (var capsuleCollider in _innerColliders) {
capsuleCollider.enabled = toggle;
}
}
}
this is the code
How come pelvis / spine & head colliders are separate and not part of innerColliders? What does innerColliders consist of?
Pelvis and spine are box colliders, head is a sphere collider and inner colliders (arms and legs) are capsule colliders. Because of that these are seperate.
Hmm - In that case I'm not entirely sure as this ToggleRagdoll is exactly what I would do too. Except I would use private List<Collider> _innerColliders; instead, so that you can add the pelvis / spine & head to that list, and save yourself writing the same line 4 times
I've never had a ragdoll have a bone fixed to the floor like yours seems to be, stretching with the ragdoll
Yea I couldn't think of that at the time π But I am sure of this is not causing my main problem
Are your inner rigidbodies kinematic by default? or non-kinematic?
If they are non-kinematic, maybe try making them kinematic by default, then when you enable the innerColliders, make them non-kinematic
Okay I'm gonna try it now
That should fix it if they were "is Kinematic = false" by default
Since the rigidbodies will be trying to constantly update physics, but your Animator will be overriding transforms. So the moment you disable the Animator, the Rigidbody velocity will be high
and you guy will go flying
they were already false π¦
Yes, so make them all true
oh okay
and then in your code
public void ToggleRagdoll(bool toggle) {
_rig.SetActive(!toggle);
_animator.enabled = !toggle;
_controller.enabled = !toggle;
_pelvisCollider.enabled = toggle;
_spineCollider.enabled = toggle;
_headCollider.enabled = toggle;
foreach (var capsuleCollider in _innerColliders) {
capsuleCollider.enabled = toggle;
}
foreach (RigidBody rb in _innerBodies)
{
rb.isKinematic = !toggle;
}
}
}
i'm trying it rn
The guy should just drop to the floor, since no forces should be applied anymore
& make sure to include your Pelvis Head and Spine Rigidbody in your public List<Rigidbody> _innerBodies; too
I just did it with getcomponent
Cool, lemme know how it goes π€
paste one of them here?
I'm trying to fix it know
Mirror?
Ah okay, yeah Idk networking
okay I'm trying to fix it xD
Best of luck with that π
Ping me here though when you manage to test the Rigidbody stuff! π
Okay π
the error was my genius getcomponent is returning null btw
foreach (var cl in _ragdollColliders) {
cl.enabled = toggle;
cl.GetComponent<Rigidbody>().isKinematic = !toggle;
}
the getcomponent line
Some of your _ragdollCollider gameobjects don't have a Rigidbody attached to it, maybe?
omg I'm gonna kill myself lol
yes yes yes that was the problem
I somehow attached the parent object (character controller) to the list
retrying it.
Lol hopefully this will be the one
pleease π
aandd
nope
that was not the problem somehow
the isKinematic thing
The only thing I can really suggest is to play the game, pause it, check all of the RigidBodies on your Enemy, check every object, make sure you didn't miss any, to set them: isKinematic = true; by default, since the code you previously had was correct
Make sure that there are no other colliders too, which are overlapping your ragdoll colliders
I just checked it and it seems normal
If you root PlayerParent object has a rigidbody, that will need to be included in the above ^
My parent object has a character controller, and I am disabling it before enabling colliders
I just fixed it
What was it? π€
I was disabling the animator, character controller etc. in the server so there was a super-tiny latency before it applies in the client. So what I did is I enabled the ragdoll physics when the packet from server arrives. Long story short, my ragdoll colliders was enabling before the character controller (root collider) disables.
And that caused all the mess
Ah I see, nice spot! π
Thank you so much for the help, I appreciate it. I think the isKinematic thing was a life saver π If you hadn't made that suggestion, it would still be working broken right now 100%
No worries, glad it's all working as intended!