0
0
Unityframework~20 mins

NavMesh Agent component in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NavMesh Agent Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this NavMesh Agent speed change?

Consider this Unity C# script snippet attached to a GameObject with a NavMeshAgent component:

using UnityEngine;
using UnityEngine.AI;

public class SpeedTest : MonoBehaviour {
    NavMeshAgent agent;
    void Start() {
        agent = GetComponent();
        agent.speed = 5f;
        agent.speed = agent.speed * 2;
        Debug.Log(agent.speed);
    }
}

What will be printed in the console when the game starts?

Unity
using UnityEngine;
using UnityEngine.AI;

public class SpeedTest : MonoBehaviour {
    NavMeshAgent agent;
    void Start() {
        agent = GetComponent<NavMeshAgent>();
        agent.speed = 5f;
        agent.speed = agent.speed * 2;
        Debug.Log(agent.speed);
    }
}
A10
B5
C0
DError: NavMeshAgent not found
Attempts:
2 left
💡 Hint

Think about how the speed property is updated step-by-step.

🧠 Conceptual
intermediate
1:30remaining
Which NavMeshAgent property controls the stopping distance?

In Unity's NavMeshAgent component, which property determines how close the agent stops to its destination?

AangularSpeed
Bradius
Cspeed
DstoppingDistance
Attempts:
2 left
💡 Hint

It is the distance from the target where the agent stops moving.

🔧 Debug
advanced
2:30remaining
Why does this NavMeshAgent not move?

Look at this code snippet:

using UnityEngine;
using UnityEngine.AI;

public class MoveAgent : MonoBehaviour {
    NavMeshAgent agent;
    void Start() {
        agent = GetComponent();
        agent.destination = new Vector3(10, 0, 10);
    }
    void Update() {
        if(agent.remainingDistance < 0.1f) {
            Debug.Log("Arrived");
        }
    }
}

The agent does not move at all. What is the most likely reason?

AThe NavMeshAgent component is disabled or missing a NavMesh to move on
BThe destination is set incorrectly with wrong coordinates
CThe Debug.Log statement stops the agent from moving
DThe remainingDistance property is not updated in Update()
Attempts:
2 left
💡 Hint

Check if the agent has a valid NavMesh to walk on.

📝 Syntax
advanced
2:00remaining
Which code correctly sets a NavMeshAgent destination?

Which of the following code snippets correctly sets the destination of a NavMeshAgent named agent to position (5, 0, 5)?

Aagent.destination = new Vector3(5, 0, 5);
Bagent.destination.Set(5, 0, 5);
Cagent.SetDestination(new Vector3(5, 0, 5));
Dagent.destination = Vector3(5, 0, 5);
Attempts:
2 left
💡 Hint

Remember the method used to assign a destination in NavMeshAgent.

🚀 Application
expert
3:00remaining
How to make a NavMeshAgent stop immediately on command?

You want to stop a NavMeshAgent instantly during gameplay. Which code snippet achieves this best?

Aagent.destination = agent.transform.position;
Bagent.isStopped = true;
Cagent.speed = 0;
Dagent.enabled = false;
Attempts:
2 left
💡 Hint

Look for the property that pauses the agent's movement without disabling it.