0

I googled what I am curious about, and didn't find anything yet.

I have my character (0, 0, 0) and enemy units are generated at random position.

And I will automatically move my character by press auto button.

While moving, begin attacking enemies if an enemy is within a certain range from my character.

Should I have all enemies list in a generic list when they are generated?

and I keep calculating the distance between my character and enemies?

I thought my character just rays around 360 degree then attacks the enemy found from the ray.

but i guess there's better way to do it.

Any ideas?

Phiru
  • 39
  • 1
  • 8
  • Well, you could just create your enemies grouped under an empty GameObject, pass it to your character through a public variable, and every Update() check the distance between the character's position vector and the enemies' (which will be children of the empty GameObject). Only attack if this distance is smaller than your threshold. This sort of "naive search" is easy to implement, though can be costly if you later need to do more calculations per enemy. If you need scalability, you may want to look into a grid-based neighbour search, which will be a bit lengthier to code, but faster to run. – Serlite Jul 18 '14 at 03:41
  • Thanks!! I will try "naive search" then look up grid-based neighbour search. Thanks again. – Phiru Jul 18 '14 at 04:46

0 Answers0