Moving in a Arch

I have a enemy that, when the player is within a certain distance, the enemy will move away, trying to escape the player based on the dir ( player.pos - enemy.pos )

Of course, I have the problem of the enemy getting stuck on walls and in corners (in a square room).

My question is, how do i calculate a arch movement that, when the enemy hits a wall, they will move at an angle away from the wall but also curving around the player. I’m hoping that this will fix the problem of getting stuck against walls and corners.

A better way put, possibly

When the enemy hits a wall or some other obstacle, it will look for an escape in a direction at least 90 degrees away from the player’s position relative to the enemy.

Thanks!

(I have already tried rays and changing the dir when x or z is 0, it works for corners but not when the character is diagonally to the enemy when the enemy is caught in a corner )

What you want is a pathfinding solution. The way you proposed is okay, but it can lead to further complications… it’s usually better to just have an enemy decide on a new place where it should go and then calculate the path to get there.

There are multiple good solutions out there for this. Unity Pro has a pathfinding solution built-in, and Aron Granberg wrote a good one that you can find on the Asset Store.