- Home /
 
How do i make a Rag doll hit reaction System?
HI, I have created a simple car game in Unity, and I'm adding the finishing touches to end the development. I have already made a car controller, programmed wheel colliders and cameras, I just would like to know how to add a hit reaction rag doll system to the civilians on the sidewalk so when they get hit by a car a rag doll is triggered and they go flying.
Answer by shadowpuppet · Apr 13, 2017 at 10:54 PM
A few ways to do this but I think the simplest ( for me ) is to have a trigger collider on the civilians with a script to instantiate a ragdoll. 1. make a copy of your civilian model and use the ragdoll wizard to create a ragdoll version of that civilian. drag that into your prefab folder to make it a prefab. 2. have a rigidbody and a collider on your car and tag it something...like "car" 3. put a script like the one below on each civilian. when the car collides with the civilians trigger ( and script) it destroys the civilian and replaces it with a ragdoll.you can use the same script for each civilian, just drag the appropriate ragdoll into the "prefab" slot
     using UnityEngine;
     using System.Collections;
     
     public class GenericCivillianHurt : MonoBehaviour {
     
         public GameObject prefab;
     
         void OnTriggerEnter (Collider other) {
             if(other.tag == "Car")
 {
           Instantiate(prefab, transform.position , transform.rotation);
                 Destroy(gameObject);
                 
 
         }
     }
 
 
              Your answer
 
             Follow this Question
Related Questions
GUI script problem 2 Answers
Character Controller to Ragdoll when HP = 0 2 Answers
How to create a custom Ragdoll. 0 Answers
Ignore Bones in Animation 1 Answer