Hi y’all! I’m trying to make a rotation/aiming script for my players in a 2D game (hatebin), and so far it’s working! It can detect one enemy automatically and continuously point at it it.
My question is, is there a way to make it so that it can point at the closest tagged player (and change its target accordingly), without modifying much of the code structure?
What I currently think I know, is that I would need to:
a) Make an array of all (P2-tagged) objects in Start(), and
b) Instead of getting the first tagged gameobject it sees as the rotationTarget, use a closestTarget-finder (Finding the vector lengths between the gameobject the script it’s on and the targets, and choosing the one with the shortest one to be rotationTarget/closestTarget I’m guessing) script in Update().
I’m a beginner and did this mostly off of tutorials (Hence why I can’t just go and do it, despite knowing roughly what to do), so basic explanations/tutorials/code would be greatly appreciated.
Any help is more than welcome, thanks!