Hey there. So I watched the great "Basic-AI-Tutorial Series" and customized it for my personal need on a 2D Plattforming Game.
What do I want to do?The Main-System of the AI is pretty much the same like in the Tutorials of BadSeedGames, only the Movement-FSM and the Orientation-FSM are changed, but the Problem isn't the Movement-FSM it's the Orientation. Here's mine:
What am I doing? So, first of all I'm checking if the Enemy is headed to the Left or the Right, that I'm checking with the XScale of the Enemy-Position and depending on the value the Raycast is firing left or right.
This is actually working, but the problem is the System itself. The Raycast only starts firing if the Character is in Range, and then it is stuck in it's direction (Left or Right).
This is the "normal" behaviour:
1. Enemy is patrolling left to right , no Raycast
2. Player comes from the Left, Enemy is heading in Players direction
3. Player is in Range, Raycast is Firing to the left and hits the Player
4. Other States are triggered (Chasing etc.)
Fine.
And this is the "unnormal" behaviour:
1. Enemy is patrolling left to right , no Raycast
2. Player comes from the Left, Enemy is heading in Players direction
3. Player waits till Enemy comes to the point where he's turning himself around to patrol in the opposite direction.
4. Player follows Enemy, which is patrolling now to the right.
5. Player is in Range, Raycast is Firing to the
right, although Player is on the Left side of the Enemy
6. Enemy is stuck in the "Raycast"-Action, because there is nothing to hit on the other side.
The Enemy stops only Raycasting when the Player is out of Range again, which is fine, but it's kind of dumb when the Enemy is facing the opponent but isn't chasing him...
Any ideas how one can solve this issue?
I thought about rotating the Ray but I don't know exactly how to do that.