Hey guys. I have an extremely basic AI setup where enemies run over to the Player and attack him. This kind of works, but it's unrealistic. I need somebody to explain to me a very basic way of having the enemies go around one another in order to get to the Player, as oppose to just running at him and pushing him away. Could somebody actually just tell me how I should approach this rather than directing me to a premade tutorial? Also, I don't want any of those fancy AI systems like Angry Ant's, just something to have the enemies walk around each other. Any ideas?
Well for a simple local collision detection I guess it could go like this:
- Face target position(waypoint?)
- Move forward
- Raycast a few units forward every (x) time.
- if collision:
- Rotate (v) degrees
- Launch timer of (t) time.
- Move forward(modified direction).
- On timer end, face initial target position and resume walk.
Instead of rotating (v) degrees, you could also set a temporary waypoint.
Of course that's a very simplistic concept and you can enhance it as much as you like. For example:
- If collider in front is dynamic(can move). Maybe you could 'slow down' instead to allow it to clear the area then resume.
- Once the front raycast hit. You could launch a series of raycast at various angle to determine the 'shortest escape route' and rotate/set waypoint accordingly.
OR cheat and just add another, bigger, collider, if(rarely) applicable. That's what I can think of right now. I'm curious as to what solutions other users have.
What I've done with decent results is to have OnCollision between enemies make them sidestep left or right (away from the other guy) for a few frames, then resume tracking the player. What happens is when 6 of them rush you from one direction, they jostle each other into a circle around you, or a line if they are still coming at you.
My code for "is this guy left or right of me" is based on distance from a line (the line the way the enemy is facing.) If you want fancier, you can have a short raycast for a pre-emptive side-step. But, those tend to look a little jerky, like you are bouncing off an invisible wall.