Hi guys! I am making a zombie fps game. So far, there’s nothing wrong, except that the ragdoll occationally freezes in it’s animation pose when i kill the zombie, unless the player does a goomba stomp. How do I solve this?
I use Unity version 3.5.6, and mixamo’s free zombie model.
Heres the ragdoll, health and animation scripts:
Health:
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour
{
[SerializeField]
int _maximumHealth = 100;
int _currentHealth = 0;
override public string ToString()
{
return _currentHealth + "/" + _maximumHealth;
}
public bool IsDead { get{ return _currentHealth <= 0; } }
PlayerStats _playerStats;
EnemySpawnManager _enemySpawnManager;
void Start ()
{
_currentHealth = _maximumHealth;
GameObject player = GameObject.FindGameObjectWithTag("Player");
_playerStats = player.GetComponent<PlayerStats>();
}
public void Damage(int damageValue)
{
_currentHealth -= damageValue;
if (_currentHealth < 0)
{
_currentHealth = 0;
}
if (_currentHealth == 0)
{
if(tag == "Player"){
Destroy(GetComponentInChildren<NightVision>());
Destroy(GetComponentInChildren<MuzzleFlash>());
Destroy(GetComponentInChildren<MuzzleLight>());
Destroy(GetComponentInChildren<GunBang>());
Destroy(GetComponent<CharacterMotor>());
Destroy(GetComponent<FPSInputController>());
Destroy(GetComponent<MouseLook>());
Destroy(GetComponent<RifleWeapon>());
Destroy(GetComponent<PlayerGui>());
Destroy(GetComponent<CharacterController>());
}else{
GameObject spawner = GameObject.FindGameObjectWithTag("Spawner");
_enemySpawnManager = spawner.GetComponent<EnemySpawnManager>();
_enemySpawnManager._maxZombies--;
_playerStats.ZombiesKilled++;
Animation a = GetComponentInChildren<Animation>();
a.Stop();
Destroy(GetComponent<EnemyMovement>());
Destroy(GetComponent<BossAnimation>());
Destroy(GetComponent<CharacterController>());
Destroy(GetComponentInChildren<EnemyAttack>());
}
Ragdoll r = GetComponent<Ragdoll>();
if (r != null)
{
r.OnDeath();
}
}
}
}
Ragdoll:
using UnityEngine;
using System.Collections;
public class Ragdoll : MonoBehaviour {
void Start ()
{
DisableRagdoll();
}
void DisableRagdoll()
{
Rigidbody[] allRigidbodies = GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody r in allRigidbodies)
{
r.isKinematic = true;
}
}
void EnableRagdoll()
{
Rigidbody[] allRigidbodies = GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody r in allRigidbodies)
{
r.isKinematic = false;
}
}
public void OnDeath()
{
EnableRagdoll();
}
}
Animation:
using UnityEngine;
using System.Collections;
public class EnemyAnimation : MonoBehaviour
{
Animation _animation;
void Start ()
{
_animation = GetComponentInChildren<Animation>();
string animationToPlay = "";
switch (Random.Range(0, 3))
{
default:
case 0:
animationToPlay = "Move1";
break;
case 1:
animationToPlay = "Move2";
break;
case 2:
animationToPlay = "Move3";
break;
}
_animation[animationToPlay].wrapMode = WrapMode.Loop;
_animation.Play(animationToPlay);
_animation[animationToPlay].normalizedTime = Random.value;
}
void Update () {
}
}
Any help would be greatly appreaciated!