Advanced Tower Defense Targeting

The only possible way I can think of making this work is through a new feature:

(thought of this while making another td game: each emitted object gets an id which keeps increasing, so if I want to find the enemy in front, what if i could extract an id based on proximity and use it to filter which enemy to target? this would need proximity id output and extractor id input.) though this wouldn’t fix the problem completely.

I want tower defense proximity targeting, but it can tell which enemy is in front. @JR01?

3 Likes

Seems really easy, just have it that when you send it out it gives it a number starting at 1 and just increases by 1 for each one you send out. Then have their number sent to the tower, and have the lowest value be attacked (can also work with highest). Then when you figure out which one to attack get the X and Y of it and boom you have a targeting system. then put the X and Y values into a filter, if they are greater/passed the reach of the tower get the next lowest ID and continue on. You could use proximity but it would cause a lot of lag if it’s in the enemy to see if they are in the range of the tower (same for ray casting).

1 Like

If you have any questions/think there’s a flaw just ask and I’ll try to answer or fix it.

1 Like

Massive flaw: some enemies are faster than others so they will get in front even though they have a different id, also i have no easy way to extract the id of it (knowing me i would use distance formula).

1 Like

different speed is a different question. give me a sec I’ll fix it.

1 Like

Add a collision block, when it hits that enemy sends a message to it through Last Contacted object. That will update its ID to the one it just hit, and send a message back to give the object now in second place its old ID.

1 Like

wait nvm, though i still have no way to get the id

Not the towers, the other enemies.

i’m not able to extract the id of the object since i’m using proximity.

The ID is given when you first spawn them in

1 Like

So you want me to make a list of position x and y and sort them out based on id?

And then use distance formula to make sure it’s within range?

1 Like

When you find the enemy with the lowest ID have it send its X and Y to the tower, If it’s within range attack it. So yes.

1 Like

I’m going to try this out and hope it works, i’m still a slight beginner at lists so i may need to come back here for help.

1 Like

I don’t think lists have to be used for this, but if you have questions I’m happy to help. (lists may be needed, but I would have to think about it more to know if it is needed or if it would make things easier)

1 Like

I don’t see how it’s possible without using two number lists of pos x and y as a global. Can you explain how? I would rather not have to use lists if I don’t have to.

When you detect which enemy is in the front, send a message to it to give its X and Y to the tower (through global blocks to constantly update), that way you don’t need to constantly keep track of their X and Y.

1 Like

You can place multiple towers meaning that if another tower could only reach enemy in 26th place then it wouldn’t work, also this would apply if a tower couldn’t see the enemy in 1st as it would target nothing.

1 Like

If 1st is out of reach then look for 2nd, then 3rd, etc. But this would cause problems if they reenter the range of the tower. I’ll think about it some more then reply if I figure out how to fix it.

1 Like

This does still use lists bc otherwise I’d need 1000 different globals and different filters so what if I searched for 1st until it’s 150 distance away then I moved on through others until I found one, and to fix reentering I would keep checking for the ones in front during the time I start checking for other ids.

1 Like