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

2020/1/14

My problem with decimal speeds

Nate2002 Nate2002

2020/1/14

#
In a game I'm making. I want my character to move down in a decimal speed, but it just turns in a big circle and doesn't fall like it should.
public class Bag extends SmoothMover
{
    private double BagSpeed = 0.5;
    /**
     * Act - do whatever the Bag wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(BagSpeed);
        turn(3);
        
        if (Greenfoot.isKeyDown("right"))
        {
            setLocation(getX()+3, getY());
            

        }
        if (Greenfoot.isKeyDown("left"))
        {

            setLocation(getX()-3, getY());

            

        }
    }    
}
Nate2002 Nate2002

2020/1/14

#
It's supposed to rotate a bit, but not like it has been
danpost danpost

2020/1/14

#
Nate2002 wrote...
It's supposed to rotate a bit, but not like it has been
You probably need to use getExactX and getExactY instead of getX and getY in your setLocation lines. As is, you are killing the precision by negating the fractional part of the coordinates.
Nate2002 Nate2002

2020/1/15

#
It works. Thanks danpost
You need to login to post a reply.