Maybe this is a super-noob question, but I’m trying to get ragdolls to fall from the sky and be destroyed when the parent collider hits the ground. Each ragdoll character model is childed to a parent GameObject which holds the box collider that I’m using for OnTriggerEnter detection, and after that collider collides with the ground, the ground triggers a Destroy(other.gameObject) on the ragdoll.
The expected behaviour is that the ragdoll falls from the sky, hits the ground and is destroyed that same frame.
The actual behaviour is that the ragdoll falls from the sky, hits the ground, then bounces around a bit before finally getting destroyed after a second or two.
The issue seems to be that the ragdoll is falling faster than the parent (and the relevant box collider), leading to the ragdoll bouncing around for a bit after it hits the ground as the parent game object/box collider catches up, which finally allows the ground’s OnTriggerEnter to destroy the ragdoll.
Hopefully I explained that well enough, and ultimately my question is, how do I stop that from happening? Like, how can I get the ragdoll to be destroyed on the same frame as hitting the ground as opposed to a second or two later? Thanks!
You may use the Unity - Scripting API: Transform.GetChild (unity3d.com) in the parent object (and get child object link in Start() or Awake() or when it is attaching) and destroy it after triggering but it will be not beauty solution. Always is better to directly control the object triggering in it. Depend on what logic you have in the screen. It is more difficultly to phisics engine to calculate inherited objects if they are mooving together with speeds. It is more complex case.
I’ve done only a little rag doll stuff w tutorials and ragdoll wizard, and it all worked well, so I never dig deeper.
But I was always lacking a full understanding, where I would enable a fine working ragdoll, but I would then have this rouge bean collider from the original character floating away with random velocities…but not effecting anything. I’d like to know the best practice as well or revisit that, sounds similar to your question.
But, writing it out as you did, it sounds like you can just instead set the trigger to the chest collider of the ragdoll (or any ragdoll part collider ) or perhaps update the main colliders position to the chest collider position as it’s falling.
Don’t know exactly about colliders, but chest is tied to legs when run. It is like a a pump.
It looks like I figured it out!
At first I tried doing using GetChild() to update the main collider’s position to the ragdoll’s position like y’all suggested (… I think? Not 100% sure if that’s what m00nandvenus was suggesting, or if you had something else in mind). While that did in fact solve the problem of the collider and ragdoll falling at different speeds… it also lead to the ragdolls falling at mach speed for some reason.
But it turns out that setting the drag and angular drag of the parent object’s Rigidbody fixed the issue. I guess the parent was being affected by drag more than the ragdoll?
A second solution that I found (which I needed once I started adding forces to the ragdolls to get them to ragdoll as they fell to the ground) was to add a fixed joint to the parent GameObject and attach it to the hips of ragdolls’ models.