Bird
Raised Fist0
Unityframework~20 mins

Waypoint systems in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Waypoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output of this waypoint index update code?

Consider a Unity C# script that moves an object through waypoints in a loop. What will be the value of currentWaypointIndex after running the Update method once if currentWaypointIndex starts at 2 and there are 4 waypoints?

Unity
int currentWaypointIndex = 2;
int totalWaypoints = 4;

void Update()
{
    currentWaypointIndex = (currentWaypointIndex + 1) % totalWaypoints;
}
A3
B4
C2
D0
Attempts:
2 left
💡 Hint

Think about how the modulo operator (%) works with the total number of waypoints.

🧠 Conceptual
intermediate
1:00remaining
Which statement best describes the purpose of a waypoint system in Unity?

Choose the best description of what a waypoint system does in a Unity game.

AIt controls the lighting and shadows in the scene.
BIt automatically generates 3D models for the game environment.
CIt defines a set of points that an object can follow to move along a path.
DIt manages user input from the keyboard and mouse.
Attempts:
2 left
💡 Hint

Think about how characters or objects move along predefined paths.

🔧 Debug
advanced
2:00remaining
Why does this Unity waypoint movement code cause the object to stop moving after the first waypoint?

Examine the code below. The object moves to the first waypoint but then stops. What is the cause?

Unity
public Transform[] waypoints;
private int currentWaypoint = 0;
public float speed = 5f;

void Update()
{
    transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypoint].position, speed * Time.deltaTime);
    if (transform.position == waypoints[currentWaypoint].position)
    {
        currentWaypoint++;
    }
}
AThe waypoints array is empty, so the object has nowhere to move.
BComparing Vector3 positions with '==' can fail due to floating point precision, so the condition never becomes true after the first move.
CThe speed variable is too high, causing the object to skip waypoints.
DThe code never resets currentWaypoint, so it goes out of bounds causing an error.
Attempts:
2 left
💡 Hint

Think about how floating point numbers behave when compared for equality.

📝 Syntax
advanced
1:30remaining
Which option correctly declares a list of waypoints in Unity C#?

Choose the correct syntax to declare a public list of waypoints as Transforms in Unity C#.

Apublic List<Transform> waypoints = new List<Transform>();
Bpublic List waypoints = new List<Transform>();
Cpublic List<Transform> waypoints = List<Transform>();
Dpublic List<Transform> waypoints = new List();
Attempts:
2 left
💡 Hint

Remember how to instantiate generic lists in C#.

🚀 Application
expert
2:00remaining
What is the output of this Unity C# code that cycles through waypoints with wrap-around?

Given the code below, what will be the value of currentWaypoint after calling NextWaypoint() three times starting from 0, if there are 3 waypoints?

Unity
int currentWaypoint = 0;
int totalWaypoints = 3;

void NextWaypoint()
{
    currentWaypoint = (currentWaypoint + 1) % totalWaypoints;
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint

Calculate the index step by step using modulo arithmetic.

Practice

(1/5)
1. What is the main purpose of a waypoint system in Unity?
easy
A. To change the color of an object randomly
B. To move an object smoothly between predefined points
C. To detect collisions between objects
D. To play sound effects when an object moves

Solution

  1. Step 1: Understand waypoint system concept

    A waypoint system defines points in space for an object to move between.
  2. Step 2: Identify the main function

    The main function is to move objects smoothly from one point to another.
  3. Final Answer:

    To move an object smoothly between predefined points -> Option B
  4. Quick Check:

    Waypoint system = smooth movement between points [OK]
Hint: Waypoints guide movement, not colors or sounds [OK]
Common Mistakes:
  • Confusing waypoints with collision detection
  • Thinking waypoints change object appearance
  • Assuming waypoints handle sound
2. Which of the following is the correct way to declare an array of waypoints in C# for Unity?
easy
A. public Vector3[] waypoints;
B. Vector3 waypoints = new Vector3[];
C. public Vector3 waypoints[];
D. Vector3[] waypoints = Vector3[];

Solution

  1. Step 1: Recall C# array syntax

    In C#, arrays are declared with the type followed by [] before the variable name.
  2. Step 2: Check each option

    public Vector3[] waypoints; uses 'public Vector3[] waypoints;' which is correct syntax.
  3. Final Answer:

    public Vector3[] waypoints; -> Option A
  4. Quick Check:

    Array syntax = type[] name [OK]
Hint: Type[] name is correct array syntax in C# [OK]
Common Mistakes:
  • Placing [] after variable name incorrectly
  • Missing 'new' keyword when initializing
  • Using invalid assignment syntax
3. What will be the output of the following code snippet in Unity C#?
Vector3[] waypoints = {new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(2,0,0)};
int currentWaypoint = 0;
currentWaypoint++;
Debug.Log(waypoints[currentWaypoint]);
medium
A. (2.0, 0.0, 0.0)
B. (0.0, 0.0, 0.0)
C. (1.0, 0.0, 0.0)
D. IndexOutOfRangeException

Solution

  1. Step 1: Understand array and index

    The array has 3 points at indices 0, 1, and 2.
  2. Step 2: Track currentWaypoint value

    currentWaypoint starts at 0, then increments to 1 before logging.
  3. Step 3: Identify logged value

    waypoints[1] is Vector3(1,0,0), so output is (1.0, 0.0, 0.0).
  4. Final Answer:

    (1.0, 0.0, 0.0) -> Option C
  5. Quick Check:

    Index 1 in array = (1,0,0) [OK]
Hint: Increment index before access to get next waypoint [OK]
Common Mistakes:
  • Forgetting index increment
  • Confusing array indices starting at 1
  • Expecting an error due to increment
4. Identify the error in this Unity C# code for moving between waypoints:
public Vector3[] waypoints;
private int currentWaypoint = 0;
void Update() {
    transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypoint], 5 * Time.deltaTime);
    if(transform.position == waypoints[currentWaypoint]) {
        currentWaypoint++;
    }
}
medium
A. Using '==' to compare Vector3 positions can cause errors
B. Missing initialization of waypoints array
C. currentWaypoint should decrement instead of increment
D. MoveTowards speed should be negative

Solution

  1. Step 1: Check Vector3 comparison

    Using '==' to compare Vector3 can fail due to floating point precision.
  2. Step 2: Identify correct comparison method

    Use Vector3.Distance or check if distance is very small instead.
  3. Final Answer:

    Using '==' to compare Vector3 positions can cause errors -> Option A
  4. Quick Check:

    Vector3 equality check needs tolerance, not '==' [OK]
Hint: Avoid '==' for Vector3; use distance check instead [OK]
Common Mistakes:
  • Assuming '==' works perfectly for Vector3
  • Ignoring array initialization issues
  • Changing waypoint index direction incorrectly
5. You want an object to move through a list of waypoints and loop back to the first waypoint after reaching the last one. Which code snippet correctly updates the current waypoint index in Unity C#?
hard
A. currentWaypoint = waypoints.Length - currentWaypoint;
B. currentWaypoint = currentWaypoint + 1; if(currentWaypoint > waypoints.Length) currentWaypoint = 0;
C. currentWaypoint = currentWaypoint - 1; if(currentWaypoint < 0) currentWaypoint = waypoints.Length - 1;
D. currentWaypoint = (currentWaypoint + 1) % waypoints.Length;

Solution

  1. Step 1: Understand looping with modulo

    Using modulo (%) with array length loops index back to 0 after last index.
  2. Step 2: Analyze each option

    currentWaypoint = (currentWaypoint + 1) % waypoints.Length; correctly uses modulo to loop index safely within bounds.
  3. Final Answer:

    currentWaypoint = (currentWaypoint + 1) % waypoints.Length; -> Option D
  4. Quick Check:

    Modulo operator loops index correctly [OK]
Hint: Use modulo (%) to loop waypoint index [OK]
Common Mistakes:
  • Using > instead of >= for index check
  • Not resetting index properly causing errors
  • Decrementing index instead of incrementing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard