Checking for nearest instances in any direction
Hello! I am in a similar situation to my previous posts; I have an idea of how to get something to work, but I am missing one element to make it work smoothly. The issue I have today is I am looking to find the nearest specific instance in any direction. In theory, all I need is the code below (written as pseudocode)
with(instances){
if point_direction(other.x,other.y,self.x,self.y) = ideal direction
and distance from self to other < stored id
stored id = self
However, I feel like constantly checking possibly a dozen or more objects against each other per room would be a headache. So instead, I have the below code;
if(radar_segment_size != 0){
// Done as to not divide by 0
`for(var dir = radar_dir; dir < 360; dir += 360/radar_segment_size){`
// dir = direction, radar_dir is the starting direction to check for instances according to the original instance.
`try{`
// That 0,0 in the x2 and y2 is what i need to solve
collision_line_list(self.x,self.y,0,0,checked_object,false,true,radar_objects,true)
//Afterward, make the connection with the first instance in the collision list radar_objects
`} catch(noInstanceFound){`
`}`
`}`
// sorry for the messed up code; I still do not know how to get reddit's code block to work... :/}
So with all of that being said, here is my issue:
I need to figure out essentially how to create an x and y value that give the direction of the dir value, while also having the x and y value reach the edge of the room. How do I get that x and y value?