My player have a line of sight and all objects between the white lines, turns red. To compute this, the following conditions are met: if the angle between the yellow line and the red line are small or equal to the angle between the yellow line and the white line above, then the object is considered to be inside the line of sight. It also works if the object are below the white line. Here is the code:
def _getTeta(obj_1, obj_2): deltaX = (obj_1.centerx - obj_2.right) deltaY = (obj_2.top - obj_1.centery) return math.acos(deltaX / math.sqrt(deltaX**2 + deltaY**2))
Obs.: centerx and right are X values and centery and top are Y value; all of them representing values encountered under certain points of each object's rectangle.
Then, I do:
if _getTeta(platform.rect, self.rect) <= _getTeta(abovePoint, self.rect): return True
where above point is the point in which forms the white line on the top, and platform is the object to be checked.
However, as the second image shows, it doesn't work if the line of sight are inverted in the X axis. The problem is that I don't know how to set values right so it could also work when the player is looking to the left.
Let me know if I'm not being clear in my question! Thanks!