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

2021/3/26

Player is glitching while fall...

Genota Genota

2021/3/26

#
Hello I got a problem. When I let my Player climb a ladder it works fine, but sometimes he glitches like for example falling out of the world or fall surprisingly fast, when I go off the ladder... Player class:
{
private int vSpeed = 0;

public void act
{
if(isTouching(Ladder_Long_Function.class) == false)
fall();
if(isTouching(Ladder_Long_Function.class) && Greenfoot.isKeyDown("up"))
        {
            setImage(myGif3.getCurrentImage());
            setLocation(getX(), getY()-5);
        }
}
public void fall()
    {
        setLocation(getX(), getY() + vSpeed);
    }
}
Risen Risen

2021/3/26

#
Line 6 should be:
if(!isTouching(Ladder_Long_Function.class && !isTouching(Floor.class))
or
if(!isTouching(Ladder_Long_Function.class && getY() < your floor coordinate)
"!" before function is the same " == false" after fuction.
Genota Genota

2021/3/26

#
Thank you for your answer. Unfortunately a syntax error message shows up: "bad operand types for binary operator '&&' first type: java.lang.Class<Ladder_Long_Function> second type: boolean" What can I do to fix that?
Risen Risen

2021/3/26

#
Genota wrote...
Thank you for your answer. Unfortunately a syntax error message shows up: "bad operand types for binary operator '&&' first type: java.lang.Class<Ladder_Long_Function> second type: boolean" What can I do to fix that?
Sorry, my bad. I've done a mistake in my code. This is right
if(!isTouching(Ladder_Long_Function.class) && !isTouching(Floor.class))
You need to login to post a reply.