ID:161926
 
I was trying to think of a way to force the movement of a mob, if they are standing still. Reason being, I don't want 50 mobs lined up in a line, I'd at least like them to move a bit, it just looks nicer IMO. I tried making a variable, and setting/unsetting it on move, and in the AI, if it was set to one, then move and set to zero, but that didn't work real well. Any thoughts?
DivineTraveller wrote:
I was trying to think of a way to force the movement of a mob, if they are standing still. Reason being, I don't want 50 mobs lined up in a line, I'd at least like them to move a bit, it just looks nicer IMO. I tried making a variable, and setting/unsetting it on move, and in the AI, if it was set to one, then move and set to zero, but that didn't work real well. Any thoughts?


Compare the current time with the last time they moved and calculate their chance of moving based on the length of time that has passed.


Alternatively use a perlin noise generator to control movement frequency possibly.
You had the right idea about modifying a variable when a mob moves, but instead of being a boolean that variable should store the last time a mob moved.

Here's what I'd do (untested):

mob
var/tmp

/*
A variable that stores
the last time this mob
moved.
*/

last_movement_time

Logout()
DoNotIdle()
return ..()

New()
. = ..()
DoNotIdle()

Move()
. = ..()
if(.) last_movement_time = world.time

proc
DoNotIdle()

/*
This is a loop that runs as long as a client isn't connected to this
mob. If ten seconds (last_movement_time + 100 1/10th seconds) have
passed since the last time this mob moved, it'll step randomly.
*/



spawn while(!client)
if(last_movement_time + 100 < world.time)
step_rand(src)
sleep(1)


If you want the gap between each movement to be random instead of a set 10 seconds, you can replace this line

if(last_movement_time + 100 < world.time)


With this:

if(last_movement_time + rand < world.time)


Where rand is the time it takes being idle to automatically move in 1/10th seconds.