Skip to main content
Game Physics – Complete Beginner to Advanced Guide
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 Rigidbody of the object entering the trigger and check its .mass property.
csharp
123456789101112131415
public float requiredMass = 50f;
private float currentMassOnPlate = 0f;

void OnTriggerEnter(Collider other)
{
    Rigidbody rb = other.GetComponent<Rigidbody>();
    if (rb != null)
    {
        currentMassOnPlate += rb.mass;
        if (currentMassOnPlate >= requiredMass)
        {
            OpenPuzzleDoor();
        }
    }
}

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 Axis of the hinge so it only rotates forward and backward.
  • Set the Limits (e.g., -45 degrees to +45 degrees).
Now, the player can literally walk into the lever, and their character's Rigidbody mass will physically push the lever down!

5. Detecting Joint Angles

If a physical lever is pushed down, how does the code know the puzzle is solved?
  • You read the angle of the Hinge Joint in the Update loop.
csharp
12345678910
public HingeJoint leverJoint;

void Update()
{
    // If the lever is pushed all the way to 45 degrees
    if (leverJoint.angle >= 45f)
    {
        Console.WriteLine("Lever Activated!");
    }
}

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 stiff SpringJoint) 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
123456
[ 10kg Crate ]   +   [ 40kg Player ]
      \                   /
       \                 /
   [ TRIGGER ZONE (Requires 50kg) ]
               |
         [ DOOR OPENS ]

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
12345678910111213141516171819
class CharacterPusher : MonoBehaviour
{
    public float pushPower = 5.0f;

    // A built-in Unity event that fires when a CharacterController hits something
    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        Rigidbody body = hit.collider.attachedRigidbody;

        // Ensure the object has a Rigidbody and isn't frozen
        if (body == null || body.isKinematic) return;

        // Calculate the push direction (ignore vertical pushing)
        Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);

        // Apply force to the box based on our speed
        body.velocity = pushDir * pushPower;
    }
}

11. Practice Exercises

  1. 1. Why is it important to check the rb.mass property inside a puzzle trigger rather than just relying on OnTriggerEnter?
  1. 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 the mass 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.

16. Next Chapter Recommendation

Our rigid physics are solid. But what about soft physics? Proceed to Chapter 13: Water, Fluids, and Environmental Physics.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·