Gravity is a pulling force. Gravity can be between one game object and another, or be programmed to "pull" straight down to simulate gravity on game objects as if they were on a planet.
Gravity can be simulated in a platform game by adding the value of a gravity variable to the value of a vspeed variable. The thing to remember that gravity is being used to accelerate the vspeed in one direction (either up or down).
Just like using vspeed with y, you must first give gravity a value and then add it to vspeed somewhere in your code. Remember, the acceleration of gravity is measured in pixels per game loop.
Along with moving a game object using vspeed and y, the gravity code would look like this :
//not GML
vSpeed = vSpeed + gravity
y = y + vSpeed
If you want to limit the amount of vspeed, you can use a threshold or cage.
Objects all fall at the same rate, excluding other forces such as wind resistance, no matter their mass. Therefore, a stone falls as fast as boulder.
Wind resistance is calculated using the surface area facing the wind.
Related Pages
- crashing
- jumping
- platform game
- vspeed
Links
- Gravity at the Game Maker Wiki
To Do
- Planetary gravity, 360 gravity
| Categories: Game Physics |