I have an AI script for my enemy which has character controller:
Its aim is to follow the player and It actually does
But when the ai meets certain situations like what is on the attached picture:
It gets stucked!
My question is :
How can i make the enemy “stop following the player and turn” then “after turning follow the enemy”?
Please help!
A* Pathfinding is what you need : 1
The current script your using directly follows the target no matter what, pathfinding consists of way points that allow the enemy to move by the way points to its target.
If you don’t want to go into pathfinding - which is the ultimate way anyway - you can use steering behaviours.
While your guy is heading to the player, you have two raycasts on each side of the NPC and if the cast returns true, you have a hit, rotate the NPC by an angle.
It is just a basic solution that will not fix entirely the issue and there could be (will be) situations where your guy is just stuck.
But it is an easy way.