• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows distance_to_object in the left or right side of the player

I need a get right or left side of distance_to_object(Pak). For example if distance_to_object(Pak) < 80 only in the left side of the player.


(distance_to_object(Pak) < x - 80) // ?????
 
Don't use distance_to_object() for this type of thing, you should write your own distance checking function when you require more granular control like this:
Code:
var _instances_to_the_left = [];
with (Pak) {
   if (x >= other.x-80 && x < other.x) {
      array_push(_instances_to_the_left,id);
   }
}
// The local variable _instances_to_the_left now holds an array with all the instances of Pak that are within 80 pixels to the left of the instance running this code
 

TsukaYuriko

☄️
Forum Staff
Moderator
That will be 80 pixels rectangular distance. If you're looking for circular distance, keep your code structure the way it is (though note that this only works for one instance of the object being checked, not multiple - that would require an iterative list-based approach like in the post above), but filter out anything with an x coordinate greater than the calling instance's x coordinate.

Familiarize yourself with the coordinate system, e.g. that negative x is left, positive x is right, negative y is up and positive y is down. By combining this logic with simple comparison operators, you can easily check against the basic cardinal directions.
 
Top