In my game, a player must defend a building from attacking enemies. The ground enemies spawn at random places around the building, and they all walk towards the building to start attacking it with their axes:
agent.SetDestination(target.position);
target.position
is the position of the building object.
It makes sense of course that the enemies try to reach the center of the building, but they should attack the surface. I tried adding
if (distance <= attackDistance)
to make sure the enemies respect a minimum distance, but since the building is not a sphere this doesn't work very good.
What's the proper way to do this?
RaycastHit.point
is below theattackDistance
, then attack. – Draco18s no longer trusts SE