ID:151515
 
So I was implementing my AI and came across the wander proc I had and was thinking how unnatural that is and how dumb of characters it makes.
//real simple code 
Wander()//will wander around while area is active and it doesnt have a target
while(!target&&active)
if(AI&AOS)
FindTarget()
dir = 1 << rand(0,3) // pick a random direction
var/turf/T = get_step(src, dir)
var/area/A = T ? (T.loc) : null
if(A && loc && A.active)
step(src, dir)
sleep(rand(3,6))

Ive tried have them walk more in a direction for a bit and changing directions, but still doesnt seem right

So any ideas on how to make it seem a little more natural. Maybe instead of doing the steps do something like have it choose a random turf in their area and do a walk_to that location.
One good way to do it is, unless something is blocking one of those places to step, only allow them to move in a direction adjacent to the one they're currently facing. For example, if they are currently facing north, they can only move northwest, north, and northeast. This allows them to move in a more natural-looking path

It's simple to calculate this, as well, though the proc allows for a little more than the directly-adjacent directions (it does default to this, though).
proc/AdjacentDirections(dir, max_angle = 45)
. = list()
for(var/angle = -max_angle, angle <= max_angle, angle += 45)
. += turn(dir, angle)
In response to Popisfizzy
In addition to what Popisfizzy suggested,you can add a chance to rotate a little extra instead of moving forward.

I would also recommend that you actually give you AI something to do.

Give each mob a home starting location to which it always returns.

Give each mob curiosity. Meaning, it moves around randomly until an obj gets within range. The mob then has a random chance to be interested in that obj. If it is interested, it moves toward that obj. You can even apply this interest to players. The same type of animal could ignore the player one time and then attack them later making every encounter an unknown.

If your trying to go the distance with AI, consider each mobs needs and then supply those. (Food, Water, Shelter). Your mob can then constantly work (walk around looking for) those needs.

When players come across your AI driven mobs, they will often find them eating, drinking, or sleeping which gives your world a little more submersion.

ts
In response to Tsfreaks
those are some good ideas, ill keep that in mind as I update my AI
In response to Tsfreaks
Tsfreaks wrote:
I would also recommend that you actually give you AI something to do. [...]

It's important to mention not to actually do this when no player is around to appreciate it, since that would be an utter waste of resources.
If you want to make it seem to players that the NPCs are doing stuff, you can simply simulate it by affecting the NPCs and their whereabouts when a player begins to approach deactivated NPCs.
In response to Kaioken
Good point. This sort of approach is better in towns and places where you can appreciate the busy AI.

Most people don't stand by and watch monsters as much as fly in and kill them.

Could make for a good way to introduce "puzzles" of sorts.

A player could go in and attack or it could hang back and monitor the AI for a bit. After some observation, the player could make a move when the AI has set down its axe to go out and collect berries. You could add additional logic which determines if the mob makes a run for their weapon when sensing the approaching player.

Regardless, you don't want the AI always starting in the same place so pick a random location, a random obj of interest (not the player), and spawn the AI. When it spawns , it will be in the middle of doing something right as the player comes into view.

ts
In response to Popisfizzy
Ok so I implemented this and I like the way it looks, but one thing im having trouble with now is trying to figure out how to not add the direction to the list if the mob cant go that way. There is a boundary of the area that he can walk in so not just dense objects (but might be dense objects also)

Heres the exit code for the Area Exit
Exit(mob/NPCs/M)//stops all NPCs from exited their area
if(istype(M,/mob/NPCs))
if(M.AI&~FOLLOW)
return 0
return ..()