- Home /
3rd person controller - stopping animation on death
I am looking for a good technique to stop the looping idle animation after I play my death animation on a 3rd person controller. Currently the character dies and falls over, but then bounces right back as idle anim kicks in looping.
Without your script that handles character animation, little can be done. Although the solution is as simple as checking whether the character is dead before animation.CrossFade("Idle");
.
script below. I am killing the character with "P" in this example. I am currently using ClampForever to stop animation on death. This still allows me to move the dead guy around with the controller.
I am comfortable scripting the state engine for the character, detecting death after X damage for example.
The more specific question I have is, what is the best practice for 'killing' the character's 3rd person controller from the standpoint of animation, movement, etc. Should you destroy the object and create new to re-spawn? I know these are big topics. I am new and just looking for some pointers or references I should look into.
function Start () { animation["attack3Weapon"].layer = 1; animation["attack3Weapon"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
animation["attack3HitCombo_BWeapon"].layer = 1; animation["attack3HitCombo_BWeapon"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
animation["deathWeapon"].layer = 1; animation["deathWeapon"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.ClampForever; }
function Update () { if(Input.GetButtonDown("Fire1")){ //attack animation animation.CrossFade("attack3Weapon");
// //attack function // var hit : RaycastHit; // if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward),hit)){ // Distance = hit.distance; // if ( Distance < $$anonymous$$axDistance){ // hit.transform.Send$$anonymous$$essage("ApplyDamage", TheDamage, Send$$anonymous$$essageOptions.DontRequireReceiver); // } // } }
if(Input.GetButtonDown("Fire3")){
animation.CrossFade("attack3HitCombo_BWeapon");
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P)){
animation.CrossFade("deathWeapon");
}
}
Answer by lighting · Mar 18, 2013 at 07:52 AM
I assume you are using Unity 4.0+ with mecanim system. If so create in Animator state machine 2 states for this: Idle and Death. Create one-way transition from Idle to Death and in transition's condition place Death = true, where Death if flag of Boolean type. Then from script you trigger this Death to be true using animator.SetBool("Death", deathFlagInScript) - look for mecanim reference for more details.
Thanks! I am going through the macanim tutorial now.