CHAPTER 04
Intermediate
Gravity and Falling Systems
Updated: May 16, 2026
25 min read
# CHAPTER 4
Gravity and Falling Systems
1. Introduction
Gravity is the anchor of the virtual world. Without it, characters float away into the void. However, programming gravity is not as simple as subtracting a set amount from the Y-axis every frame. True gravity is an *acceleration*—the longer you fall, the faster you go, until you hit a maximum speed known as terminal velocity. Furthermore, in genres like Platformers, strict realism feels terrible; jumps must be snappy, controllable, and responsive. In this chapter, we will master Gravity and Falling Systems. We will learn the math behind gravitational acceleration, implement a dynamic jump arc, and cap our falling speed.2. Learning Objectives
By the end of this chapter, you will be able to:- Differentiate between constant falling speed and gravitational acceleration.
- Implement a basic gravity system using vertical velocity.
- Code a responsive jump mechanic based on an initial impulse.
- Implement Terminal Velocity to prevent game-breaking physics glitches.
- Understand "Arcade" gravity tuning for platformer games.
3. Gravitational Acceleration (The Math)
If you drop a rock, it doesn't fall at a steady 5 mph. It starts at 0 mph, then 10 mph, then 20 mph. Gravity increases Velocity over time.-
Standard Earth gravity is approximately
-9.81 m/s².
-
In code, we must continually subtract this value from our vertical velocity (
velocity.y).
csharp
4. The Jump Mechanic (The Impulse)
Jumping is essentially fighting gravity with a massive, instantaneous burst of upward velocity.-
When the player presses 'Jump', you instantly set
velocity.yto a high positive number.
- In the following frames, gravity will automatically chip away at that positive number, slowing the player down at the apex of the jump, and eventually pulling them back down.
csharp
5. Terminal Velocity (The Speed Limit)
If a player falls off a massive cliff, gravity will keep accelerating them endlessly. If they reach 10,000 mph, they will instantly teleport through the ground collision box because they moved too far in a single frame (Tunneling).- You must enforce Terminal Velocity: a maximum falling speed.
csharp
6. Arcade Tuning (The "Mario" Jump)
Real gravity feels "floaty" in video games. To make a platformer feel responsive:-
1.
High Gravity, High Jump: Double the gravity to
-20fso the player falls fast, and double the jump force to compensate. This makes the jump feel "snappy."
-
2.
Variable Jump Height: If the player lets go of the jump button early, artificially multiply the gravity or cut the
velocity.yin half. This allows for short hops versus high jumps.
7. Visual Learning: The Jump Arc
txt
8. Best Practices
-
Resetting Velocity on Landing: The moment your character touches the ground, you MUST set
velocity.y = 0(or a very small negative number like-2fto keep them stuck to the floor). If you let gravity build up while standing on the floor, the moment the player walks off a ledge, they will shoot downward at Mach 3!
9. Common Mistakes
-
Grounded Checks: The hardest part of jumping is writing the
isGroundedboolean. If your code thinks the player is slightly in the air because of a bumpy floor, they won't be able to jump. Always use a generous Raycast or a SphereCast pointing downward from the player's feet to reliably detect the floor.
10. Mini Project: Build a Custom Gravity Controller
Objective: Write a script that handles jumping, gravity acceleration, and landing.
csharp
11. Practice Exercises
-
1.
Why must gravity be added to
velocityover time, rather than added directly toposition?
- 2. What is Terminal Velocity, and what critical physics bug does it prevent?
12. MCQs with Answers
Question 1
When programming a jump in a custom kinematic controller, what mathematical action should you take the exact moment the player presses the jump button?
Question 2
A character stands on a platform for 10 minutes. When they step off the edge, they instantly teleport to the bottom of the level at a million miles an hour. What code did the developer forget to write?
13. Interview Questions
- Q: Explain the mathematical difference between linear movement (speed) and gravitational movement (acceleration). How is this represented in code?
- Q: What is "Variable Jump Height" (where holding the jump button goes higher than tapping it)? Explain the logic used to achieve this arcade physics mechanic.
- Q: Describe the concept of "Tunneling" in physics engines. How does enforcing a Terminal Velocity mitigate this issue for fast-falling objects?