Hello everyone, first off, I am very new to programing and am still studying but could really use a hand with this one. Thanks in advance.
So I have this great waypoint script Im using and I dont know how to alter it so I can get the mob to stop moving when it gets in a variable defined range of any object with a certain tag. Any help is greatly appreciated! Thanks!
This is the current script im working with:
var waypoints : Transform;
var speed : float = 5.0;
var Turnspeed : float = 2;
var ChangeWaypointRange : float = 5;
var endPoint : Transform;
private var targetwaypoint : int;
function Start() {
if(waypoints.Length <= 0){
Debug.Log("No waypoints");
enabled = false;
}
targetwaypoint = 0;
endPoint = waypoints[targetwaypoint];
}
function Update () {
var distanceFromEndpoint = Vector3.Distance(endPoint.position, transform.position);
if (distanceFromEndpoint <= ChangeWaypointRange)
{
targetwaypoint ++;
}
if(targetwaypoint>=waypoints.Length)
{
targetwaypoint = 0;
}
endPoint = waypoints[targetwaypoint];
var rotateDirection = Quaternion.LookRotation(endPoint.position - transform.position);
transform.rotation = Quaternion.Lerp(transform.rotation,rotateDirection,Turnspeed*Time.deltaTime);
transform.Translate(Vector3.forwardspeedTime.deltaTime);
}