2
votes

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?

1
You could raycast against the building's collider and when the distance between the Unit and the RaycastHit.point is below the attackDistance, then attack.Draco18s no longer trusts SE

1 Answers

0
votes

You can put empty gameObjects around the building as little "attack points"

But a more proper way to do this is to make it so when enemies detect a collision with the walls, they go into an attacking state.

Other than that, I'm not exactly sure what you mean. Are they attacking a compound around the building? Are they just bashing an axe on the walls of a building?

I could help you further if you gave more information.