Download

AI Searching for Player Help?

Hi, I’m currently trying to write the enemy AI so that when the player is in view of the enemy and in range, they will follow you, but when you leave their view range, they will search the area they last saw you in for 20 seconds, then if they still haven’t seen you they will go back to their original position and start their patrol again, but instead when the player leaves the enemies range, they just go into an endless loop of the ‘SearchingForPlayer’ event and following the ‘True’ in the branch, so something is going wrong and not setting the ‘Searching for Player?’ boolean to false.

I have no idea what’s causing the issue, I thought I’d narrowed it down to the ‘Retriggerable Delay’ because I tried rerouting the Branch True into ‘Searching for Player’, skip the retriggerable delay and go straight into the next branch and it fixed one issue by actually going back to the original position, but now the enemy doesn’t search the player’s last known location, it just goes straight back to the original patrol. I’ve tried using a normal delay but that didn’t make a difference, and even if it did work, a normal delay wouldn’t allow the search to be started from the beginning of the 20 seconds if the player is found and lost again.

I tested it again while skipping the retriggerable delay, but on the second test it just went back to what it originally did and continuously searched for the player and never went back to the original spot. I then tested it for a THIRD time and a completely different issue arose, this time the enemy started following me when I got into its sight, then when I left its vision range the enemy lost me and went straight back to the original position (didn’t search for me, just went straight back), and when I tried to get its attention again it turned around and walked in a different direction every time I stepped in front of it, like it was angry with me and tried to get away. I have no idea what’s going on.

A second issue I’m having with this system is the ‘On Player Being Searched For’ not doing anything. The radar is white by default, turns red when you are being targeted, and is supposed to turn yellow when they are searching for you, but after you’ve been spotted it just stays red, and doesn’t turn yellow when you’re being searched for, or back to white when they’ve lost you, although in the third test I mentioned when it started to ignore me after it lost me the first time, the radar went back to white. It seems like it can’t make its mind up how to behave.

Any help would be greatly appreciated, thank you!

Search for player loop … You’re not breaking the loop with logic.

There’s nothing visible in your flow that counts the delay time and does a branch conditional check … IS search time >= 20…true : set searching for player false.


On Player being searched for … need to see the code.

Thank you, I figured it out with a LOT of trial and error, I did what you said and it fixed that problem but brought more but now I’ve got it working to a standard I’m happy with, haha, and the second issue I figured out too, that was a simple mistake I made but didn’t notice.

Thanks for helping me again

Sometimes you just need to walk away, take a break. Come back to it with fresh eyes.