Sign in to follow this  
TianWolf

Unity An odd problem with AI

Recommended Posts

Hello, I've making AI for a game. But there's this weird thing that happens when the player passes the while it faces the opposite direction the player is facing, sorta like cars passing each other on a two way street but one is stationary. What happens is the AI will veer into the players lane (keeping the car analogy), but past the player so that it is behind him. The AI will then turn to face the player, who is walking away from the AI, catch up, get within killing distance and game over. What makes that weird is that the AI should be within killing distance even before moving behind the player. Any ideas on why this might happen?

I am using:
Unity
Behave behavior tree utility
Aron Granberg's A* pathfinding project

Share this post


Link to post
Share on other sites
After touching the screen for half a minute I'm still clueless... maybe some piece of code or a more detailed description of what you are doing ?

Share this post


Link to post
Share on other sites
I realize there isn't much to go on so I made a video. There is no sound but it should still help.

http://www.livestream.com/TianWolf/video?clipId=pla_cff0d67c-2a97-412b-a598-dda6f76e1622&utm_source=lslibrary&utm_medium=ui-thumb

Share this post


Link to post
Share on other sites
I haven't used Behave or that particular A* implementation. Perhaps the behaviour is set up wrong, e.g. attack from behind, go to player then attack without checking whether already in attack range, monster perception range wrong. Or perhaps you are pathfinding to the player's last position without considering motion? Maybe either pathfinding or behaviour trees have a large delay between re-evaluating? If those tools provide some debug it would be helpful, e.g. show the co-ordinates it's currently pathfinding to, show which branch of the behaviour tree it's currently in.

Share this post


Link to post
Share on other sites
There are two actions under the attack sequence. One gets in range by sending the player position to the pathfinding component. The just ends the game, for now. Action 1 will succeed when close enough to the player. Action 2 never actually succeeds because it ends the game. Using the debugger, it is apparent that Action 1 does not succeed the first time it is in range (it never goes to action 2). Instead what happens is the AI will see the player which satisfies the condition for the decorator that is connected to our problematic sequence. It'll go to the player, even bumping into him (as seen in video). The player goes past our enemy character which also makes him leave the AI's line of sight. The AI turns around (because of hearing) and sees the player again which means it is now using the same branch as earlier, the debugger confirms this, but this time everything works as it should. The AI catches up to the player and ends the game once close enough.

I realized a picture of the tree would be pretty helpful:
http://i.imgur.com/45ayM.png

Edited by TianWolf

Share this post


Link to post
Share on other sites
Here's a few things that may help with this (or similar issues):[list]
[*]Re-path more often. This could be because it's heading towards a historical player position.
[*]Include a small amount of prediction when pathing towards the player.
[*]Allow action 1 to work off hearing as well as sight.
[*]Increase the monster's field of view.
[*]Add a head look so the monster can still see the player when nearby and slightly off-centre.
[*]Add a proximity warning to the monster's senses, e.g. it knows where the player is if within attack distance, even if not facing the player.
[*]Add some sort of sweeping attack which doesn't require the monster to be directly facing the player.
[/list]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this