Hi all
I am making a game with a bullet object that looks for the nearest enemy. This works.
But, how do i target the second-most nearest, and even third-most, so that I can fire at them at the same/similar time.
Do you have a suggestion?
Thanks
Develop games in your browser. Powerful, performant & highly capable.
once you have the UID of the first closest, take it out of the SOL and go again. Then take the first two out and go again. There is probably a more efficient way by ordering them by distance and then taking the top 3.
yours winkr7
I often use for each ordered to do that. Here it would shoot at the 3rd closet. This method is also useful when you want to do stuff with the n closest like it sounds like you are.
For each enemy ordered by distance(player.x,player.y,enemy.x,enemy.y)ascending Loopindex+1=3 — stop loop — shoot
thanks both! got it working thanks to your input.