- Home /
Detect if player is left or right of enemy
So basically I'm making this game (sort of like super smash bros I guess but 8bit) and I need some basic enemy AI. How can I make a script that detects if the player is to the left or right of the enemy, so I can make the enemy move towards the player?
Answer by MichaI · Mar 10, 2019 at 12:52 AM
Simply compare x coordinates of enemy and player:
if(enemy.transform.position.x > player.transform.position.x){ //Move left } else { //Move right }
lol I didnt even think of that idk why (I think I'm overcomplicating trying to get enemy AI to work)
Your answer
![](https://koobas.hobune.stream/wayback/20220612193259im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make Player jump (like in a 2D fighting game) 2 Answers
Transferring momentum from one player to another player? 1 Answer
Camera Goes white when moving with player, 1 Answer
PLayer not landing afteer jumping,Player jumping by clicking button 1 Answer
What is the purpose of this function? "protected virtual void Init() { }" 1 Answer