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

2023/6/13

How do i stop my Mario from jumping to high?

Ima_pan_cake Ima_pan_cake

2023/6/13

#
  if (Greenfoot.isKeyDown("space")){
            jump();
            
        }
        
        
    }
    public void jump(){
        vspeed= jumper;
        fall();
        
    }
It does work when you press space to jump but when you hold space he wont stop until you let go. How do i stop this?
danpost danpost

2023/6/13

#
Ima_pan_cake wrote...
<< Code Omitted >> It does work when you press space to jump but when you hold space he wont stop until you let go. How do i stop this?
You need to add another condition to jump -- mainly, is the actor standing on the ground (or on top of an object). Easiest way to check this is to apply gravity and fall first; then, check for obstacles. If the vertical speed is positive and an obstacle is found, than the on ground state is met and you can then check for the jump key. My Jump and Run Demo w/Moving Platform illustrates how this is done.
You need to login to post a reply.