This site requires JavaScript, please enable it in your browser!
Greenfoot back
Raiden
Raiden wrote ...

2016/9/19

How do I make random AI?

Raiden Raiden

2016/9/19

#
Trying to make an AI that will move wait a second or so then move again, how do I do this? this is what I have as of yet
move(4);
 setRotation(Greenfoot.getRandomNumber(360));
danpost danpost

2016/9/19

#
Just use a timer int field to count act cycles. Have the act method increment it. When its value reaches 55 or so, have the actor move:
if (timer == 55) move(4);
// or
if (timer == 55)
{
    move(4);
}
Having the rotation of the actor randomly set each act cycle will cause it to act spastically pretty much in one place. Either limit to turning in small increments or limit the changing of rotation to once every few moves.
You need to login to post a reply.