Wandering monster

Hey guys,

for my upcomming horror game I need a script for a monster A.I that wanders around, and when it sees the player it’s going after him.

Can someone give me a good start? :face_with_spiral_eyes:

I won’t give you actual code since I don’t know which language you prefer. However.

If you want something simple to get you started. The simplest way to do it would be to have the monsters spawn when the player is nearby. Pick a random direction on creation and just walk straight. When it gets to a wall, go another direction. Then have either a trigger or distance detector (Vector3.distance) so when the player gets close the mob could chase after the player using (Transform.Lookat). This is by no means a Polished or really “Acceptable” method for AAA or even AA games since the mobs are likely to get stuck because they will simply come straight after the player (It may not be a problem in your game if its like my example below with limited ledges etc). But its something to get you started and if nothing else would get you something to prototype with.

Here’s an example of a game I did a while back using that method.

If you wanted code examples I’d be more than happy to help (they would However be in C#).

Well, I already have the following, but I want that he is walking around on sight,.

Gotcha, Well depending on your coding ability and how complex you want the system you have a few options to pursue for something more advanced.

Little More Complex

One thing I plan on doing in the next update for Get Away! (Next Halloween Probably) is adding some more advanced AI that will avoid objects to get you using Raycasting to make the zombies avoid objects by simply moving away or trying to go around the objects. More or less it would end up acting more like a Depth First Search (without the part that makes it Depth first like Nodes). This method is not the best path to take (no pun intended) but its fairly easy to implement if you don’t have PRO handy.

Little More complex Than That!

The Angry Bots project has Node Based AI if I recall. That wouldn’t be a bad route especially if you mixed in the above with it. But basically the AI from that demo would be good for learning something a little more effective than just the “Wander around like an idiot” AI.

All In Method

A* is basically the “All Bets Are Off” AI. this would easily be the most accurate and most difficult to implement (on your own). But this AI Search finds the shortest possible path and navigates to it avoiding obstructions. And Luckily there is code already out there that does this and you’d just need to pop it in your game and code/setup the rest. This system and its documentation are found over at arongranberg.com.

PRO Method

If you have PRO, All you have to do is implement the built in system. And then you’ll be good to go.

End of the day, when it comes to implementation you’ve got options. I’m sure someone will chime in and give more as well (As well as correct any mistakes or misinformation I had since its been a while since my AI classes).