![greenfoot gravity greenfoot gravity](https://i.ytimg.com/vi/s0ORj87eFEM/hqdefault.jpg)
#Greenfoot gravity code
If there are any problems with it you can ask me because i made the code to be gravity for a character not a ball so i had to change a few things. Final int so it cant be changed unless you hard code it. Gamingprotramp7 wrote.private final int GRAVITY = 1 //gravity. Also don't forget to change the names so it matches up and doesn't break. Return isOnGround //returns so that it knows when to stop making the character fall If (getOneObjectAtOffset(imageWidth / -2, imageHeight / 2, Platform.class) != null || getOneObjectAtOffset(imageWidth / 2, imageHeight / 2, Platform.class) != null) isOnGround = true //checks if ball is on a platform (change "platform" to name of the platform you have ex: ground, floor, etc.) Int imageHeight = getImage().getHeight()
![greenfoot gravity greenfoot gravity](https://i.ytimg.com/vi/nDqH6DIHezM/maxresdefault.jpg)
Public boolean isOnSolidGround() //checks if character is on solid ground doubles gravity over time to make it more realistic Velocity = 0 //sets velocity to 0 if its on solid ground so the character doesnt fall through objectsĮlse velocity += GRAVITY //makes character fall if not on solid ground.
![greenfoot gravity greenfoot gravity](https://i.ytimg.com/vi/WzSQ_KwwFzY/maxresdefault.jpg)
If (isOnSolidGround()) //checks if boolean isOnSolidGround() is true SetLocation(getX(), getY() + velocity) //makes character fall depending on velocity We are going to fill in the missing code in the Jumper class and. Final int so it cant be changed unless you hard code it. Presently, our player character is stuck at the bottom of the screen.