Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to play an animation with waypoints

$
0
0
Hi there I am creating an underwater game, and I have set up a waypoint system for a fish model. The waypoint script works okay, but the fish is facting the wrong direction when it moves. So I added a simple animation to it, now it does not move. How can I have the fish move in the waypoint system and still have the animation play? Here is my script: `var waypoints : Transform[]; private var current_waypoint : int = 0; var speed : int = 10; function Update () { var target: Vector3 = waypoints[current_waypoint].position; var moveDirection : Vector3 = target - transform.position; if(moveDirection.magnitude < 2) { current_waypoint++; if(current_waypoint >= waypoints.length) { current_waypoint = 0; } } else { rigidbody.velocity = moveDirection.normalized * speed; } transform.LookAt(waypoints[current_waypoint]); }`

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>