AI Patrol
Hi I am very new to javascript and I have this code that allows me to move a game object from one place, Idle then move back and so forth.
I need to have multiple checkpoints so I can make a set path for the AI to follow, I need the AI to look at each checkpoint so It looks like they are walking and have the animations all in this code. I have my own animations for idle, walking, and running. I'm not sure how I can implement it into this code.
What I need is multiple checkpoints set up, the object that is following this path to be following the path and looking where it is going (for example the next checkpoint) and have the animations implemented into the code.
#pragma strict
// Transforms to act as start and end markers for the journey.
var startMarker: Transform;
var endMarker: Transform;
// Movement speed in units/sec.
var speed = 4.0;
// the wait time between waypoints
var waitTimeBetweenWaypoints : float = 1;
function Start ()
{
Patrol();
}
function Patrol()
{
while (true)
{
var time : float = 0;
var lerpValue : float;
// set the position of to the startMarker)
transform.position = startMarker.position;
// move object from startMarker to endMarker)
while ((transform.position != endMarker.position) && (time < speed))
{
time += Time.deltaTime;
lerpValue = (time / speed);
transform.position = Vector3.Lerp (startMarker.position, endMarker.position, lerpValue);
yield;
}
// set the position of to the endMarker)
transform.position = endMarker.position;
yield WaitForSeconds(waitTimeBetweenWaypoints);
time = 0;
// move object from endMarker to startMarker)
while ((transform.position != startMarker.position) && (time < speed))
{
time += Time.deltaTime;
lerpValue = (time / speed);
transform.position = Vector3.Lerp (endMarker.position, startMarker.position, lerpValue);
yield;
}
transform.position = startMarker.position;
yield WaitForSeconds(waitTimeBetweenWaypoints);
}
yield;
}
Your answer
Follow this Question
Related Questions
Editing an AI patrolling script 1 Answer
Need support on my basic navmesh ai script to follow the player at a certain distance 1 Answer
Monsters are walking around without my permission, why? 0 Answers
Enemy AI for Shooting Game 1 Answer
How do I get my AI to chase the player?,How do I go from patrolling to chasing the player? 3 Answers