Hi everyone, I need a hand to solve a problem in my game. As the title suggests, the enemies must necessarily remain at a certain distance from the player. The chasing function already works, but when I go towards the enemy, the latter does not move away. The game is 3D and uses navmesh and navmesh agents for enemies. Thanks so much
Hi,
Here’s one solution on high level - In your enemies logic check the distance to the player. If the player is within certain distance, make the enemy try to find a new target where it will move to. I don’t know anything about your game or how you want the enemies to behave, but you could just calculate a vector from the player to the the enemy, and then extend the vector so that it is at least outside the perimeter you want to retain. Then check if this point is a valid navmesh location where your enemy can move and make the enemy move there. Also implement some mechanism to find an alternative location for the enemy or otherwise handle the situation.