- Home /
Basic enemy AI for 2.5D Platormer
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?
Answer by FLASHDENMARK · Apr 03, 2011 at 09:31 AM
You can use: transform.eulerAngles or transform.rotation
Either of thoes should do the trick :)
Where would I add the rotation as I have tried adding them but it does some weird things
Your answer
![](https://koobas.hobune.stream/wayback/20220613120456im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Top Down Shooter Enemy AI using raycasting 1 Answer
Make enemy more intelligent 0 Answers
Collisions not working when player stands still 1 Answer
Enemy not rotating when inside range 1 Answer