CHAPTER 12
Intermediate
Physics-Based Puzzles and Gameplay
Updated: May 16, 2026
25 min read
# CHAPTER 12
Physics-Based Puzzles and Gameplay
1. Introduction
Physics shouldn't just be for bullets and ragdolls; it should be a core component of level design. Games like *Portal*, *Half-Life 2*, and *Zelda: Breath of the Wild* built their entire identities around emergent physics puzzles. Dropping a heavy block onto a pressure plate to open a door, or stacking crates to reach a high ledge, provides the player with highly intuitive, rewarding gameplay. In this chapter, we will master Physics-Based Puzzles. We will explore the mechanics of interaction, construct mechanical levers using physics joints, and program weight-based trigger systems.2. Learning Objectives
By the end of this chapter, you will be able to:- Design weight-sensitive pressure plates using Mass calculations.
- Construct interactive mechanisms (levers and doors) using Hinge Joints.
- Implement Push/Pull mechanics for heavy objects.
- Program an object-grabbing system (like the Gravity Gun).
- Prevent common physics exploits in puzzle design.
3. Weight-Based Triggers
A standard Trigger (OnTriggerEnter) just detects if an object is inside it. But a puzzle plate needs to know if the object is *heavy enough*.
-
We must extract the
Rigidbodyof the object entering the trigger and check its.massproperty.
csharp
4. Mechanical Joints (Levers and Hinges)
Instead of animating a drawbridge or a lever, you can build it using physics!- Attach a Hinge Joint to the lever.
-
Set the
Axisof the hinge so it only rotates forward and backward.
-
Set the
Limits(e.g., -45 degrees to +45 degrees).
5. Detecting Joint Angles
If a physical lever is pushed down, how does the code know the puzzle is solved?-
You read the
angleof the Hinge Joint in theUpdateloop.
csharp
6. The "Gravity Gun" (Grabbing Objects)
How do you pick up a physics box and carry it around?- Bad Way: Making the box a child of the player. This ruins the physics simulation, and the box will clip through walls.
-
Good Way: Create a
FixedJoint(or a very stiffSpringJoint) between the Player's hands and the Box. The box becomes magically tethered to the player, but if the player turns too fast and the box hits a wall, the physics engine calculates the collision properly and the box will drop!
7. Visual Learning: The Weight Plate Puzzle
txt
8. Best Practices
- Visual Feedback: A physics puzzle is frustrating if the player doesn't know it's working. If a player places a 10kg block on a 50kg plate, the plate should visually sink downwards *slightly* (perhaps 20% of the way) using C# Lerp, showing the player they are making progress.
9. Common Mistakes
- The Stacking Exploit: If you require the player to reach a ledge 10 meters high, and you put 10 tiny crates in the room, the player will try to stack them. As mentioned in Chapter 9, stacking 10 rigidbodies causes massive instability. The tower will violently explode, frustrating the player. If you want a stacking puzzle, use Snap-To-Grid mechanics, or limit the required stack to 3 items.
10. Mini Project: Build a Pushable Object System
Objective: Allow a Kinematic character to push a Rigidbody box. If your player does not have a Rigidbody (they use a Character Controller), they cannot physically push a box. You must write a script to apply fake force!
csharp
11. Practice Exercises
-
1.
Why is it important to check the
rb.massproperty inside a puzzle trigger rather than just relying onOnTriggerEnter?
- 2. What type of Physics Joint should be used to create a realistic, physical trapdoor that swings downward when stepped on?
12. MCQs with Answers
Question 1
You want the player to pick up a heavy metal box. Instead of making the box a child of the camera (which causes it to glitch through walls), what physics component should you use to tether the box to the player while maintaining solid collisions?
Question 2
When writing code for a physics-based lever, which property of the HingeJoint must you read in the Update loop to determine if the player has fully pushed the lever down?
13. Interview Questions
- Q: Explain the architecture of a weight-based pressure plate. How do you track the total mass dynamically when multiple objects enter and exit the trigger zone?
- Q: Contrast the implementation of an animated door versus a physics-driven door using a Hinge Joint. What are the emergent gameplay benefits of the physics-driven approach?
- Q: A developer complains that their Kinematic character simply clips into Rigidbody crates instead of pushing them. Explain why the physics engine ignores the character, and how to resolve this using scripted force application.
14. FAQs
Q: How do I stop players from pushing a puzzle box off a cliff and breaking the game? A: Always add a massive "Kill Trigger" at the bottom of the cliff. When the puzzle box hits it, the trigger resets the box's position back to its original spawn point and zeroes out its velocity!15. Summary
In Chapter 12, we turned the physics engine into a playground. We learned how to extract themass property from rigidbodies to create intelligent, weight-sensitive puzzle plates. We utilized Hinge Joints to build physical levers and drawbridges that react naturally to the player's momentum. Finally, we learned how to architect interaction systems—from tethering objects using Fixed Joints to manually applying push forces from Kinematic characters. Our levels are now emergent and interactive.