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

2016/10/31

accelerate over time (missile)

brothermic brothermic

2016/10/31

#
Hello, how to accelerate my missile shot by my tank over time? the idea is when i shoot the missile it move a little time very slowly forward and then accelerates to its target. next code didnt work:
public class Missile extends Actor
{
    int speedTeller = 0;
    public Missile(int rotation)
    {
        setRotation(rotation);
    }
    /**
     * Act - do whatever the Missile wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        while(speedTeller <= 30){
            move(1);
            speedTeller++;
        }
        while(speedTeller > 30 && speedTeller < 150){
            move(5 + speedTeller/30);
            speedTeller++;
        }
maybe other idea?
Super_Hippo Super_Hippo

2016/10/31

#
Try to use 'if' instead of 'while'.
danpost danpost

2016/10/31

#
You probably do not need an 'if' or a 'while'. You can just use something like this:
public void act()
{
    move(1+speedTeller/6); // adjust '6' as needed
    speedTeller++;
}
You need to login to post a reply.