First, make a variable called direct then do the following:
One way you could do this is to make a timer. Then when the timer is finished, have a piece of code like this:
- Code: Select all
direct=rand(2);
If I remember correctly, rand(2) mightcreate a random of 0 and 1 (I could be wrong on that, if you don't experience a pause for the gladiator, change the 2 to 3). Now on Draw Actor of the gladiator, do this:
- Code: Select all
switch(direct)
{
case 0:
xvelocity=-5;
ChangeAnimation("Event Actor", "Walk Left", NO_CHANGE); //this code wont work you have to do it manually. make sure its set at NO_CHANGE and not forward
break;
case 1:
xvelocity=5;
ChangeAnimation(...); //walk right
break;
case 2:
xvelocity=0;
//have him stop motion here. you can
//use animindex to determin what animation
//he's in then use that to change his animation
//to stopped.
break;
}
That should allow him to move randomly about the stage. If you want him to locate the player, you'd do this:
- Code: Select all
if(x<player.x) {
xvelocity=5;
}
This will make him go right if the player is to the right of him.
- Code: Select all
if(x>player.x) {
xvelocity=-5;
}
This will make him go left if the player is to the left of him.