Skip to main content
Mr. Helland
  • Home
  • Calendar
  • More
English
Deutsch English Español Français Tiếng Việt Русский العربية 简体中文
You are currently using guest access
Log in
Mr. Helland
Home Calendar
Expand all Collapse all
  1. 3D Game Prog
  2. 2️⃣3D Environments
  3. 09: A Mazing Puzzle (Part 3)

09: A Mazing Puzzle (Part 3)

Completion requirements
Make a submission
Due: Thursday, October 23, 2025, 11:59 PM

Learning Target

  • Add collision triggers
  • Use scripts to react to collision triggers

 


Resources

Door Models:
    • Door.blend
    • Cage Door.blend
Starter Scripts:
    • DoorMechanism.cs
    • ActivateDoor.cs
Optional Resources:
    • Toggle Switch.blend
    • ToggleSwitch.cs


Instructions

Step 1: 

Two door models have been provided. You will need to:

    • Import the models into your Models folder
    • Create original prefabs of the doors
    • Assign materials to the doors
    • Add a collision box to prevent passage by the player

Then, find 2 or 3 spots to locate doors in your maze and add them to your scene. 

 

Step 2:

It will look a lot better if our doors open, rather than just disappear. To do this, we'll create a small C# script (or use the template above). 

Note: class-level variables are called several different things in different contexts. Here are some commonly used terms:

    • class attributes
    • member variables
    • fields

Your script will need these public member variables so you can make adjustments:

    • IsOpen (boolean)
    • Speed (floating point)
    • OpenHeight (floating point)

You'll also need these two private fields to keep track of positions: 

    • upPosition
    • downPosition

Optional: 
You could use a public variable to control which direction your door moves when it is opened (e.g. up, down, left, right):

  • OpenDirection (Vector3)

You could make your door swing open instead of sliding. This is a bit more of a challenge.

Step 3:

When the game first starts, we need to store both the up and down positions for that specific door. To store the "up" position, we just need to move the starting position along the y-axis. For example,

    upPosition = this.transform.position + new Vector3(0, OpenHeight, 0);

We can slowly move from our current location to a destination position using the MoveTowards() method. This is not complete code, but shows what we are trying to do:

this.transform.position = Vector3.MoveTowards( current position of door , target position of door , distance to move this frame);

You might remember from math and science that distance = speed • time.

We already have a variable for Speed. The time would be how long has passed since the last frame update. Unity provides this information with the variable Time.deltaTime. So, the distance we need to travel can be calculated like this:

distance to move per frame = Speed * Time.DeltaTime;

We also need to use a conditional (if statement) for this to work properly in both directions. 

if(IsOpen) {
// move to the up position
} else {
// move to the down position
}

Step 4:

We need a way to tell the doors to open.

Create a Prefab Variant for one or more of your maze blocks. Add a new collision box in the player's pathway.

Change this collision box to be a trigger, but be sure to keep the others as regular colliders.

 

Step 5:

When the player hits a door trigger, we need to actually control one of the doors. Create a new C# script (or use the template above). The script will need at least two public variables:

    • Door (DoorMechanism)
    • IsOpener (boolean)
    • Optional: IsReversible (boolean)

 

You'll need to add a new function:

void OnTriggerEnter(Collider other) {

}

This function will execute whenever the player moves into the trigger collider. You will be able to tell the door to open by doing something like this:

Door.IsOpen = true;

However, you should only open the door if that is the script's current purpose. Otherwise, you should close the door.

 

IsReversible?

To make the door's operation reversible, we can use a "flip-flop" code structure in ActivateDoor.cs. It would look something like this:

if(IsReversible) {
   if(IsOpener) {
        // make this activator a closer
   } else {
        // make this activator an opener
   }
}

Don't forget to add an else statement for when the activator is NOT reversible.

Challenge:

Though it is not required, you are welcome to use the Toggle Switch and its corresponding script to add variety to your maze. It may also give you some ideas on other ways to add interest to your maze.

 


Grading

For grades A to D, all requirements need to be met for that grade band. 

Doors and Door Activators  Letter Grade 
  • All requirements for an A
  • At least one door is controlled by a toggle switch
A+

Meets these criteria:

  • There are at least 4 doors that are controllable by the player
  • At least one door is triggered by movement through the maze
  • At least one door can be opened and then closed again
  • The doors are used creatively and/or serve a useful purpose
A

Meets these criteria:

  • There are at least 3 doors that are controllable by the player
  • At least one door is triggered by movement through the maze
  • At least one door can be opened and then closed again
B

Meets these criteria:

  • There are at least 2 doors that are controllable by the player
  • At least one door is triggered by movement through the maze
C

Meets this criteria:

  • There is a door that is controllable by the player
  • The door is triggered by movement through the maze
D
Doesn't meet above criteria  Reassigned
◄ 08: A Mazing Puzzle (Part 2)
10: A Mazing Puzzle (Part 4) ►
You are currently using guest access (Log in)
Get the mobile app
Powered by Moodle