Quantcast
Viewing all articles
Browse latest Browse all 1488

How to I vary animations based on proximity?

I've written a script to animate a toon based on his location to me, with an 'idle' animation when he is out of attack range, a 'run' animation when he is within chase range, and an 'attack' animation when he is within attack range. But as soon as I enter chase range, the 'run' animation plays and the 'attack' animation never begins. (The idling animation works fine.) I think it's perhaps because my code would have both run and attack animations happen at once. Not what I want. Is there a way of saying the 'run' animation should play when less than one distance, but also stop when less than a second distance? My script is attached for reference. var Distance; var Target : Transform; var lookAtDistance = 25.0; var Damping = 6.0; var chaseRange = 15.0; var attackRange = 1.5; function Update () { Distance = Vector3.Distance(Target.position, transform.position); if (Distance > chaseRange) { idle (); } if (Distance < attackRange) { attack (); } if (Distance < chaseRange) { run (); } } function idle () { animation.CrossFade ("idle"); } function attack () { animation.CrossFade ("attack"); } function run () { animation.CrossFade ("run"); } Thanks a lot.

Viewing all articles
Browse latest Browse all 1488

Trending Articles