Tower Defense "First" Targeting Extension

This extension (thanks to @jwunderl’s sprite utils and the tilemap a* path following extensions) massively helps with tower defense games, so that when multiple sprites are following a path, you can easily determine and target the first sprite!

The extension: kiwiphoenix364/pxt-tower-targeting

Paste the “link” in the search bar at the top of the extensions page and click on the result.

One thing you’ll definitely need to make it not crash is this:
(the array of sprites of kind tower is so that all the towers attack, also, the enemiesinrange true/false piece of code is so that if there are no enemies in range, it won’t attempt to output a sprite value since there are no sprites in range to attack.)

I’ve made an example of how to use this. You might see that I’m using the arcade-sprite-data extension. This extension is very useful and probably essential if you want to have multiple towers/enemy types in your game without making too many blocks or sprite types and also to have attack cooldowns.

If you want to make an advanced tower defense game, you probably will need to have more local variables and assign them as attributes to the projectiles that the towers make (like in my tower defense project.)

could this work for ZL-targeting like in Zelda?

I updated the extension to have a new block which makes targeting even easier.

Also, @personalnote I have no idea (because I don’t play Zelda much.) I did play BOTW, but I don’t remember what ZL does. It probably wouldn’t work for that but idk and I hope you can get it to do what you want!

ZL is a targeting system where when you hold ZL it locks onto the closest enemy to make fighting easier.

No, this doesn’t work like that because it uses the paths extension. It is definitely possible to do that though, as you can just use the sprite utils extension and compare all the sprites distances to the player and see which is closest.

huh, well alright then