#Problem with Ragdoll

1 messages Β· Page 1 of 1 (latest)

jaunty finch
#

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.

twilit spoke
#

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?

jaunty finch
# twilit spoke Do you apply a force to all rigidbodies when you activate it? or just the Hips r...

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

twilit spoke
#

How come pelvis / spine & head colliders are separate and not part of innerColliders? What does innerColliders consist of?

jaunty finch
twilit spoke
#

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

jaunty finch
twilit spoke
#

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

jaunty finch
#

Okay I'm gonna try it now

twilit spoke
#

That should fix it if they were "is Kinematic = false" by default

jaunty finch
#

yes it's false

twilit spoke
#

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

jaunty finch
twilit spoke
#

Yes, so make them all true

jaunty finch
#

oh okay

twilit spoke
#

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;
            }
        }
    }
jaunty finch
#

i'm trying it rn

twilit spoke
#

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

jaunty finch
twilit spoke
#

Cool, lemme know how it goes 🀞

jaunty finch
#

just got a looot of errors

#

mirror errors btw

twilit spoke
#

paste one of them here?

jaunty finch
#

I'm trying to fix it know

twilit spoke
#

Mirror?

jaunty finch
#

network system

#

it's a multiplayer game

twilit spoke
#

Ah okay, yeah Idk networking

jaunty finch
#

okay I'm trying to fix it xD

twilit spoke
#

Best of luck with that πŸ˜‚
Ping me here though when you manage to test the Rigidbody stuff! πŸ˜„

jaunty finch
#

Okay πŸ˜„

jaunty finch
#
foreach (var cl in _ragdollColliders) {
                cl.enabled = toggle;
                cl.GetComponent<Rigidbody>().isKinematic = !toggle;
            }
#

the getcomponent line

twilit spoke
#

Some of your _ragdollCollider gameobjects don't have a Rigidbody attached to it, maybe?

jaunty finch
#

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.

twilit spoke
#

Lol hopefully this will be the one

jaunty finch
#

pleease πŸ˜„

#

aandd

#

nope

#

that was not the problem somehow

#

the isKinematic thing

twilit spoke
#

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

jaunty finch
twilit spoke
#

If you root PlayerParent object has a rigidbody, that will need to be included in the above ^

jaunty finch
#

My parent object has a character controller, and I am disabling it before enabling colliders

#

I just fixed it

twilit spoke
#

What was it? πŸ€”

jaunty finch
#

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

twilit spoke
#

Ah I see, nice spot! πŸ˜„

jaunty finch
# twilit spoke 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%

twilit spoke
#

No worries, glad it's all working as intended!