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

2021/10/1

Hey Need help With Actor Speed

Monk_08 Monk_08

2021/10/1

#
I want my actor to move faster when he eats a pill I've look at several discussions on the topic but non had this specific topic so how can I make my actor change speed
danpost danpost

2021/10/1

#
Monk_08 wrote...
I want my actor to move faster when he eats a pill I've look at several discussions on the topic but non had this specific topic so how can I make my actor change speed
To make something variable (i.e. the speed), you need to declare a variable:
private int speed = 1;
so that you can change it:
if (speed == 1) speed = 2;
(some other condition would be used to prompt the increase in speed) and move by it:
move(speed);
However, without any control, this change would be permanent. ************** Adding a timer field would be more like what is needed for the change to only be temporary:
private int speedTimer;
with control:
if (speedTimer > 0) speedTimer--; // run timer
move(1+(int)Math.signum(speedTimer));
For 2 seconds of high speed when pill is eaten:
speedTimer = 120; // set timer
Monk_08 Monk_08

2021/10/1

#
Wow thank you danpost for the quick answer every time i asked something thanks <3 Havent even thought about the timer but its a perfect addition :)
You need to login to post a reply.