I have my player who is moving in a straight line. When he hits a “waypoint” I want him to rotate to the same orientation as the waypoint and continue to move forward in his new orientation until he hits another waypoint.
I have my player moving and writing to the log when he hits a waypoint, but I don’t know how to get the orientation information from the waypoint and then apply it to the player.
When I set out to do it I thought it would be simple, but it’s not…
I’m very new to Unity and scripting, so I would really appreciate some help.
OK, so here’s what I came up with to get it to work…
private var target : Transform;
private var targetWaypoint : String;
private var wayPointNumber : int;
var speed : int = 1;
wayPointNumber = 0;
function Update () {
transform.Translate(0,0,speed*Time.deltaTime);
targetWaypoint = ("waypoint" + wayPointNumber);
target = GameObject.Find(targetWaypoint).transform;
transform.LookAt (target);
}
function OnTriggerEnter(waypointCollision:Collider){
if(waypointCollision.gameObject.tag == "Waypoint"){
wayPointNumber = wayPointNumber + 1;
}
}
This does what I need, but with LookAt it’s snapping from each target to the next. I would love to dampen the LookAt.
I have looked at the original script for the camera, but I’m not sure how to work the damping for that into what I have there. I’ve tried but couldn’t get a result…