Search Unity

Ragdoll teleports into the ground when shot.

Discussion in 'Editor & General Support' started by Mr_AgentFox, Jul 24, 2019.

  1. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    59
    Hey! My ragdoll sometimes teleports downwards a bit when I shoot it. Any advice?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class Ragdoll : MonoBehaviour
    6. {
    7.     public float health = 10f;
    8.     public Rigidbody rb;
    9.     public List<Collider> RagdollParts = new List<Collider>();
    10.     public Animator animator;
    11.     public bool isDead = false;
    12.  
    13.     void Awake()
    14.     {
    15.         SetRagdollParts();
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.  
    21.     }
    22.  
    23.     void SetRagdollParts()
    24.     {
    25.         Collider[] colliders = this.GetComponentsInChildren<Collider>();
    26.  
    27.         foreach (Collider c in colliders)
    28.         {
    29.             if (c.gameObject != this.gameObject)
    30.             {
    31.                 c.isTrigger = true;
    32.         }
    33.     }
    34. }
    35.  
    36.     public void TakeDamage(float amount)
    37.     {
    38.         health -= amount;
    39.         if (health <= 0f)
    40.         {
    41.             TurnOnRagdoll();
    42.         }
    43.     }
    44.  
    45.     void TurnOnRagdoll()
    46.     {
    47.         rb.useGravity = false;
    48.         this.gameObject.GetComponent<BoxCollider>().enabled = false;
    49.         animator.enabled = false;
    50.  
    51.         foreach (Collider c in RagdollParts)
    52.         {
    53.             c.isTrigger = false;
    54.             c.attachedRigidbody.velocity = Vector3.zero;
    55.         }
    56.     }
    57. }
     
  2. justthatrio

    justthatrio

    Joined:
    Apr 26, 2020
    Posts:
    3
    im having the same problem, did you ever find a solution?