i have a ray sensor and two objects and i need to make it be able to tell which one is farther away how?


P  <----Player

__________ <–wall

E <----- enemy

i need to tell if the player is behind the wall or in front
for the Ai i am making

so, if the ray sensor is tracking the wall, and hits closer than the position of the enemy [I would have it setup so you didn’t have to be able to hit the enemy with the ray sensor]

so, do you remember you pythagorean therorem from algebra class?

… yeah, this is a pretty simple task… in python

The three dimentional distance formula is :


or, the python version…


Just make one of the coords the position of the object that’s your ray’s owner, and make the other coord the position of the object you want to know the distance away from the ray. Then just compare the distances to see which one is closer.

You’ll need to know python and the GameLogic API to implement this.