Hi all!
I am having a big trouble customizing my patrolling AI script to fit into a Pac-Man style stealth game. My current script has parts of a tutorial and parts I wrote myself.
I think it would move better if I used CharacterController.Move, but tell me if there is a better way!
I already tried taking parts of that move script I linked, but somehow I couldn’t get it working properly…
So if you please could point me out what to do, I’m so confused with this :S Here is the script:
var waypoint : Transform[];
var speed : float = 50;
private var currentWaypoint : int;
var loop : boolean = true;
var player : Transform;
function Update ()
{
if(currentWaypoint < waypoint.length)
{
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
currentWaypoint++;
}
else
{
velocity = moveDirection.normalized * speed;
}
}
else
{
if(loop)
{
currentWaypoint=0;
}
else
{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
transform.LookAt(target);
}
function LateUpdate()
{
//This prevents the enemy from flying upwards
transform.position.y = 1.7;
}