How would I detect whether an instance is first in line?

I’m making a Tower Defense game and couldn’t figure out how to detect which one is in first place.

I dont understand, Please elaborate

How would I find the first instance in a line.
Something like this
image
How would I find this with a script?

hmm that is a tricky one, what exactly are you going to do when you have the first in line

Shoot at it depending whether it’s in the range. The range is handled by a magnitude.

I cant think of a work around for this, all i can think of is ones that will remove good features from your game eg if they all go at the same speed then you can get which one spawned first instead

Could I get the farthest one from the player?

Yes easily
textheretocharacterlimit

Go through all the character and get the distance and keep a variable storing the largest distance and the object and if you find a larger distance then set the variable over until you have gone through them all

1 Like

If you spawn them through scripts then it could be easy by putting them in tables then just looping through it.

When you add in a new enemy, insert them at the end of a given table. When you remove an enemy, remove them from said table. If you follow both of these carefully, then the furthest enemy in the level is always the enemy at index 1 of that table, whereas the last spawned enemy is always the enemy at the last index of that table.

Thats saying every enemy moves the same speed

If you can’t determine the order in any way during the creation of these parts, you can use raycasting to find the first one in a line.

Raycast to where through?
character limit

All characters wont face the same way so I don’t know if the raycast method will work.

about to say that lol
ahhhhhhhcharacterlimit

Look into this post: Attack First Target. I believe it shares a similar idea as you.

I found a solution. Here’s my code!


Thanks to @korbykobs