Hi, I am trying to create a 2.5D platform game. I am now trying to create a basic enemy AI that will make the enemy patrol an area between 2 points. I have a working AI script that makes the enemy go back and forth. The script is below.
var walkSpeed : float = 2.0;
var wallLeft : GameObject;
var wallRight : GameObject;
private var walkingDirection : float = 1.0;
var walkAmount : Vector3;
function Update () {
walkAmount.x = walkingDirection * walkSpeed * Time.deltaTime;
if (walkingDirection > 0.0 && transform.position.x >= wallRight.transform.position.x) {
walkingDirection = -1.0;
}else if(walkingDirection < 0.0 && transform.position.x <= wallLeft.transform.position.x) {
walkingDirection = 1.0;
}
transform.Translate(walkAmount);
}
However this only transforms the enemy along the x axis. What I cant figure out is how to make the enemy Rotate 180 degrees before heading in the other direction?