[Help] How can i check mathematical area?

This is a working code to detect whether the player is inside or outside the area.

67TB3

The Idea and how it works:
(All vectors are flatened (multiplied with (1, 0, 1)))
At first I create one direction vector from the position of the player to each of the corners of the area. If you draw a picture of this you will see, that in the case that the player is inside the rectangle the direction vectors look like an X, while in the case that the player is outisde the rectangle the direction vectors will all go to one side of the player.
In order to detect whether its case 1 or 2 its enough to sum up the angles between the direction vectors of adjacent corners. If the player is inside the sum will always be = 360°. If the player is outside the sum will always be < 360°.

Usage:

  • Put the corners of the area into global variable A (IMPORTANT: the Y coordinate has to be 0)
  • IMPORTANT: make sure that the corners are in circular order. Example:
    Right:
    0—1
    | . |
    3—2
    Wrong:
    0—1
    | . |
    2—3