- Home /
Help With Animation
Hello,
I have a tank that follows an array of waypoints, and I basically want it to play an animation every time it turns left or right.
So, what I'm doing right now is calculating the distance between the tank and the waypoint and if the distance is a certain number - then play 'turning' animation.
So I have this (function Update):
var dist = Vector3.Distance(transform.position, waypoint[currentWaypoint].position);
if(dist <= waypointRadius + 2){
animation.wrapMode = WrapMode.Once;
animation["tank_leftTurn"].speed = 1;
animation.Play("tank_leftTurn");
}
So basically - if tank is coming close to a waypoint, begin to turn (all my waypoints are on corners)
NOTE: The tank turns anyway as a transform, when I say 'turning' animation - I mean the animation of the wheels turning.
This works - except that the animation jumps .. its like its playing animation over and over again a few times.
I also want it to turn back (so 'speed = -1.0;') after it leaves the waypoint.
Any ideas why and how I could achieve this?
Thanks
Answer by karl_ · May 19, 2011 at 03:59 PM
If it's jumping I would assume it's because the Tank is within 2 units of the waypoint for more than a single call. Thus, the tank is being told to play the turn animation over and over until you are out of the 2 unit radius.
Your answer
Follow this Question
Related Questions
Facing moving direction using Waypoints 1 Answer
Can the animation editor create local rotational data? 3 Answers
Different animation on each wayPoint 1 Answer
Adding animation clips via script 2 Answers