Hi,
i managed to let my character jump to a certain hight. But now i want him to get back down... how can i add some kind of Gravity? I already tried to use setLocation when the Player is not grounded (touching the object ground), but after adding that function he wouldn't jump at all :
Method Grouded:
Method jump:
(if you press longer you jump higher)
1 2 3 4 5 6 7 8 9 10 11 | public boolean grounded() { if (isTouching(Boden. class )) { return true ; } else { return false ; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | if (Greenfoot.isKeyDown( "space" )) { if (grounded()) { setImage( "images/jumpking_sprungloading.png" ); a = System.currentTimeMillis(); while (Greenfoot.isKeyDown( "space" )) { setImage( "images/jumpking_sprungloading.png" ); } b = System.currentTimeMillis(); sprung = ( int ) b - ( int ) a; if (sprung > maxSprung) { sprung = maxSprung; } setLocation(getX(), getY() - sprung / 4 ); } } else { setImage( "images/jumpking_standard.png" ); } |