I am trying to move a camera along a path but change the target of the camera now and then, for example when I am at a particular waypoint; but i cannot figure out how to get that waypoint in script. I am using this to move the camera with success so far.
private var currentWaypoint : Transform;
private var currentIndex : int;
var moveSpeed : float = 10.0;
var minDistance : float = 2.0;
function Start ():void
{
currentWaypoint = waypoints[0];
currentIndex = 0;
}
function Update ()
{
MoveTowardWaypoint();
if(Vector3.Distance(currentWaypoint.transform.position, transform.position) < minDistance)
{
++currentIndex;
if(currentIndex > waypoints.Length -1)
{
currentIndex = 0;
}
currentWaypoint = waypoints[currentIndex];
}
}
function MoveTowardWaypoint() : void
{
var direction : Vector3 = currentWaypoint.transform.position- transform.position;
var moveVector : Vector3 = direction.normalized * moveSpeed * Time.deltaTime;
transform.position += moveVector;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), 4 * Time.deltaTime);
}
Just to clarify you are able to get your camera to move from waypoint to waypoint already but you want to be able to do what exactly?? Sorry maybe my brain is just not working right but I can't quite figure out what exactly you are try to do.
– Glister