I’ve been stuck thinking about a good way to implement this targeting system. I want to be able to lock on to enemies. But before that I need a way to show the player which enemies can be targeted.
I have been following along this video for reference: https://www.youtube.com/watch?v=MSSPIU7FjIU
Currently, how I’m thinking of implementing this is having a constant sphere trace from the player character to detect multiple lock-on-able enemies in front, and when the sphere trace hits a lock-on-able enemy, it will toggle the visibility of a widget on the enemy, showing the player that this enemy is lock-on-able. So when there are multiple lock-on-able enemies, all of them will have the widget visible. And when enemies leave the sphere trace, it will be toggled off.
The problem I’m having trouble with is how to deal with the case when the enemy is no longer being hit by the sphere trace. How would I go about setting the visibility of the widget on that enemy back to hidden now that it is no longer hit by the sphere trace?
Initially I’m thinking of implementing some array list like structure that will keep track of the enemies in the sphere trace and remove them accordingly when they leave? Or maybe keep 2 arrays (one for the current sphere trace state, and another for the previous sphere trace state) and constantly match them seeing if there is an enemy that left. I also am not sure how to implement these methods efficiently.
Any help would be appreciated!
Thanks in advance!