- Home /
The question is answered, right answer was accepted
Determining if something is on the Left or Right of an Object
How can I determine whether something in the world is on the left or right of an object even if the object is rotations. I have a vehicle that i'm trying to create an AI for but i need to be able to determine whether the next waypoint is on the left or right taking into account that the vehicle could be in any rotation. I can't use lootAt or similar functions.
the best simple way to determine that, will be with this simple code
//this is a variable of type transfor, which we will use to locate our player or objetc public transform player;
void Start() { //here we asign the player to the variable we created Player = GameObject.Find("Player").GetComponent();
//if player position x is less than the current objetc position x then the player is at the left else it is at the right
if (Player.position.x < transform.position.x) { Debug.Log("player is left from object"); }
else { shootRight(); Debug.Log("el player esta a la derecha del drowned"); }
Answer by DSebJ · May 11, 2013 at 11:11 PM
ahh, the Dot product, completely slipped my $$anonymous$$d, Thank you so much.