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

2021/10/29

phassing through floor and platforms

Dlantz Dlantz

2021/10/29

#
I cant seem to keep my character on the platforms when he jumps or falls and he just phasses through them at times any and all help would be appreciatable
private int speed = 5;
    private int vspeed = 0;
    private int accelaration = 1;
    
    private int acceleration = 1;
    private int jumpStreangth = 8;
/**
     * how we fall
     */
    public void fall()
    {
        setLocation (getX(), getY() + vspeed);
        vspeed = vspeed += acceleration;
    }
 
    public boolean onGround()
    {
        Actor under = getOneObjectAtOffset(0, getImage().getHeight()/2, Platform.class);
        return under != null;
    }
    
    /**
     * how we fall
     */
    public void checkFall()
    {
       if (onGround())
       {
           vspeed = 0;  
       }
       else
       {
           fall();
       }   
    }
    
    /**
     * how we jump
     */
    public void jump()
    {
       vspeed = -jumpStreangth;
       fall();
    }
danpost danpost

2021/10/31

#
As coded, the onGround method will only return true if a platform is at a specific location with respect to the jumper. But, you need a broader area to check if the platforms are not always at ground level (which your program is currently designed for). Please refer to my Jump and Run Demo w/Moving Platform to see how to better program a platformer.
Dlantz Dlantz

2021/11/2

#
I'm sorry, but im lost. at the moment i want to fix my problem with the platforms
You need to login to post a reply.