Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Jodo Kast on Sun 16/11/2003 19:06:26

Title: Wandering Character
Post by: Jodo Kast on Sun 16/11/2003 19:06:26
This is probably beginner script but, how do I make a NPC wander around the screen?

I'm not sure how to do it with the walkable areas messing it up.  NPC walks off in one direction, randomly pauses.  

This will be a 'cleaning' character.

Thanks!
Title: Re:Wandering Character
Post by: MrColossal on Sun 16/11/2003 20:03:02
in the room's repeatedly execute:

if (character[NAMEOFCHAR].walking!=1){
MoveCharacter(NAMEOFCHAR, Random(320),Random(200));
}

that should do it yes no?
Title: Re:Wandering Character
Post by: Totoro on Sun 16/11/2003 21:31:19
Quote from: MrColossal on Sun 16/11/2003 20:03:02
in the room's repeatedly execute:

if (character[NAMEOFCHAR].walking!=1){
MoveCharacter(NAMEOFCHAR, Random(320),Random(200));
}
that should do it yes no?
Would that mean the player character could do his actions while NAMEOFCHAR is sort of minding his business in the background?
Title: Re:Wandering Character
Post by: MrColossal on Sun 16/11/2003 21:35:03
yup, i've done it tons of times, it's quite neat

only thing is it's random, so they'll just walk around bumping into walls and heading off in the strange directions

so it's best for birds or cats or robots or maids

not trying to trick someone into thinking the character has an agenda
Title: Re:Wandering Character
Post by: CB.. on Mon 17/11/2003 00:55:13
many thanks from me allso  ive been doing it with all this messy stuff!

if (IsTimerExpired(1)==1)
{int ran=Random(7);
if (ran==0) MoveCharacter(GDTWO,character[GDTWO].x-36,character[GDTWO].y);
else if (ran==1) MoveCharacter(GDTWO,character[GDTWO].x+34,character[GDTWO].y);
else if (ran==2) MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y-36);
else if (ran==3) MoveCharacter(GD,character[GD].x+34,character[GD].y);
else if (ran==4) MoveCharacter(GD,character[GD].x,character[GD].y-36);
else if (ran==5)MoveCharacter(GD,character[GD].x,character[GD].y+36);
else MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y+36);
SetTimer(1,200);
}  

then put this in enters room after fade in

SetTimer(1,200);

you saved me a lot of messing around !  

great source this forum many thanks all!
Title: Re:Wandering Character
Post by: Jodo Kast on Mon 17/11/2003 05:15:48
Thank you!  I think I can make this a function then and tell a character to wander after each conversation is over.

It should also work with a group of insects I wanted swarming above the swamp!  Thanks again!