Find Object Closest To End and Beg of Path...

V

vgoat

Guest
So I have a problem I am using my path in a tower defense game and I want to implement targeting of specific enemies in a specific point on the path. I think path_position has something to do with it but, I cant figure out how to check which instance of enemy_parent (all enemies) is closest to the end of the path. Value of 1 in the path_position... If I can use this I can get the id of the object closest to the end of the path. Which I could set a tower to target that or the beginning enemy with some global value called say, global.EnemyTarget which will be in play with my selection system for choosing that. Once again I am just looking how to get the id of the object the is closest on the path (Gamemaker Paths mine is called Path_Something). Any help would be super helpful!
 
A

Aura

Guest
Code:
var i = path_get_number(path);
var inst = instance_nearest(path_get_point_x(path, i), path_get_point_y(path, i), obj_enemy);
That should do it IMO.
 
V

vgoat

Guest
So this can implement the point that is closest too beg and end with is code right? All I do is get the point that is the start of the path and one that is the end of the path? The points meaning the dots in the path view in gamemaker right? Pick the starting one and then pick the end one and that is it?
 
Last edited by a moderator:
A

Aura

Guest
Yes. If you don't understand how the functions I gave work, kindly read the following Manual entries:

http://docs.yoyogames.com/source/da.../paths/path information/path_get_point_x.html

http://docs.yoyogames.com/source/da.../paths/path information/path_get_point_y.html

http://docs.yoyogames.com/source/da...e/paths/path information/path_get_number.html

Simply using the position of the points of the path in the resource tree as the coordinates of instance_nearest() should have the same effect if the path is absolute.
 
V

vgoat

Guest
Thanks for the help I think I got this figured out now. Also this helped me get an idea to calculate strongest and weakest enemies :D This now resolved I don't now how to change this to it...
 
A

Aura

Guest
What do you mean? Please clarify. Do you want to filter enemies by their strength? ^^"
 
V

vgoat

Guest
Also just realized the code works for the most part it doesn't work relative to the path itself. It will check the coordinates of the points on the path it will check in room and not path only. For example the closest to the end will check in regards to the closest enemy with a direct path even though the enemy is on a path. It doesn't exactly do it path only.
 
Top