- Home /
Other
Ragdoll help
Hello, I am trying to make a script where the enemy turns into a ragdoll after his health is less than or equal to 0. Also, the enemy has an animation, so i'm trying to make it where the ragdoll gets disabled and the animator gets enabled, then vice versa when he dies. But I keep getting these errors that I don't under stand! If anyone can help, here is my script and errors:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class Enemy : MonoBehaviour{ public Animator death; public float health = 50f; void Start() { setRigidbodystate(true); setColliderstate(false); } public void TakeDamage(float amount) { health -= amount; if (health <= 0f) { Die(); } } public void Die() { //death.SetTrigger("IsDead"); GetComponet<Animator>().enabled = false; setRigidbodystate(false); setColliderstate(true); } void setRigidbodystate(bool state) { Rigidbody[] rigidbodies = GetComponentInChildren<Rigidbody>(); foreach (Rigidbody rigidbody in rigidbodies) { rigidbody.isKinematic = state; } GetComponet<Rigidbody>().isKinematic = !state; } void setColliderstate(bool state) { Colliders[] colliders = GetComponentInChildren<Collider>(); foreach (Collider collider in colliders) { collider.enabled = state; } GetComponet<Collider>().enabled = !state; } }
Do me a favor and set the Rigidbody and colliders arrays as normal variables. Do not just create them in your methods. That seems to be the problem.
@BenWiller1989 Thanks for helping me with this, but how might I do what you said? I'm not necessarily the person who can take plain text, and turn it into code. Do you $$anonymous$$d pasting instructions for doing this?
Answer by BenWiller1989 · Sep 04, 2020 at 09:18 PM
First of all, change Rigidbody and collider to "GetComponentsInChildren", not "GetComponentInChildren". You'd like to fill an array, not assign a single variable. And wow, you are very new right?
I was following a tutorial that might be outdated, I guess it is. Here is the tutorial: https://www.youtube.com/watch?v=zjuI5Jdzjxo&t=197s
Are you able to read the code? on my screen, it's all jumbled up with no ''return'' spaces
I am, I made ragdolls myself, so I know, what you're trying. But we need to do this step by step. Just replace the GetComponentInChildren with GetComponentsInChildren and report back, what changed.
Follow this Question
Related Questions
Disable Collider After two Second of Being Triggered and enable it again 3 Answers
Enable/disable animation 0 Answers
How do I disable all rigidbodies and colliders in a scene in unity? 2 Answers
Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer
How to change settings to a rigidbody when adding it to a gamobject? 2 Answers