Guard AI Chasing Mechanics in Unity 3D Quiz

Explore the key concepts of implementing guard AI chasing behavior in Unity 3D, focusing on player detection, movement, animation transitions, and state management in a third-person shooter setup. This quiz is designed to reinforce basic principles crucial to creating engaging and responsive enemy AI systems in game development.

  1. Determining Direction to Player

    In the guard AI script, which calculation is used to determine the direction from the guard to the player?

    1. Multiply the guard's position by the player's position
    2. Subtract the guard's position from the player's position and normalize the result
    3. Add the guard's position to the player's position
    4. Use only the player's current position without comparing it to the guard's

    Explanation: The correct calculation finds the vector pointing toward the player by subtracting the guard's position from the player's, then normalizing to get direction. Adding positions would give an unrelated point in space. Multiplying positions is not meaningful for direction. Using the player's position alone does not account for where the guard currently is.

  2. Moving the Guard AI

    Which function is typically used to move the guard in Unity's character controller when chasing the player?

    1. characterController.Move()
    2. moveCharacter()
    3. characterController.Run()
    4. Translate.Move()

    Explanation: characterController.Move() is the standard method for moving an object using the Character Controller component in Unity. characterController.Run() is not a standard Unity method. moveCharacter() and Translate.Move() are not predefined Unity functions and may lead to confusion or errors.

  3. Adjusting Movement Speed

    When making the guard chase the player, how can you increase the chase speed without affecting walking speed?

    1. Set a higher chase speed value for the running animation state only
    2. Use the same speed for both chase and walk functions
    3. Lower the time.deltaTime value
    4. Change the walking speed globally in the script

    Explanation: By setting a higher chase speed just for the running state, you ensure that the guard moves faster only while chasing, not while patrolling. Changing the walking speed globally affects all states. Lowering time.deltaTime would break time-dependent movement logic. Using the same speed for both chase and walk would prevent acceleration during chasing.

  4. Y-Axis Rotation Handling

    Why should the guard not fully rotate toward the player on all axes, especially when the player is very close?

    1. To prevent unrealistic or abrupt vertical tilting
    2. To keep the guard stationary
    3. To make the guard invisible to the player
    4. To save computational resources

    Explanation: By limiting rotation to the Y-axis, the guard only turns left and right, avoiding unnatural movement like looking up or down dramatically when near the player. Saving computational resources is not the main reason here. Making the guard invisible or stationary is unrelated to the rotation behavior.

  5. Animation State Changes During Chase

    Which animation state should be set to true while the guard is chasing the player?

    1. Jump
    2. Walk
    3. Run
    4. Idle

    Explanation: During a chase, the guard's animation should indicate running, so the Run state is set to true. Walk is appropriate for patrolling. Idle is for standing still, and Jump does not match the scenario described.

  6. Behavior When Not Alerted

    If the guard's 'isAlerted' flag is false, what should the guard do according to the script logic?

    1. Remain idle and stop all movement
    2. Start shooting at the player
    3. Chase the player aggressively
    4. Return to waypoint walking

    Explanation: When isAlerted is false, the guard returns to its original patrol behavior by walking between waypoints. Aggressive chasing and shooting are part of the alert/chase state. Remaining idle is not specified in this state.

  7. Correct Move Vector Calculation

    What should the move vector used to move the guard be composed of during chasing?

    1. Player's velocity multiplied by guard's speed
    2. Only the guard's transform.forward direction
    3. Direction to player multiplied by current movement speed and time.deltaTime
    4. Waypoint direction multiplied by walk speed

    Explanation: The movement should follow the direction to the player, scaled by speed and frame time for smooth movement. Waypoint direction is for patrolling, not chasing. Using only transform.forward ignores the player's position, and player's velocity is irrelevant for the guard's chasing motion.

  8. Purpose of Normalizing the Direction Vector

    Why is it necessary to normalize the direction vector when making the guard chase the player?

    1. To make the guard stop when close to the player
    2. To double the guard's movement speed
    3. To make the guard invisible while running
    4. To ensure the guard moves at a consistent speed regardless of distance

    Explanation: Normalizing the vector gives it a length of one, so multiplying by speed results in movement at a consistent rate, no matter the distance to the player. It does not cause the guard to stop, become invisible, or double its speed.

  9. What Happens in Shooting Radius

    When the player enters the shooting radius, what does the current guard AI behavior do before shooting functionality is added?

    1. The guard starts shooting instantly
    2. The guard jumps over the player
    3. The guard continues to run in place, unsure of what to do
    4. The guard resumes waypoint walking

    Explanation: With no shooting logic yet, the guard animation keeps running once the player enters the shooting radius, since there's no code to specify a different action. The guard does not yet shoot, walk away, or jump in this situation.

  10. Ensuring Time-Based Movement

    Why is Time.deltaTime used when moving the guard in Unity's update loop?

    1. To make movement depend on the player’s health
    2. To synchronize the guard’s speed with the camera
    3. To keep movement consistent across different frame rates
    4. To slow down the animation transitions

    Explanation: Time.deltaTime scales movement so that changes occur smoothly and at the same rate, regardless of the frame rate. It is not related to player health, camera movement, or slowing animations. Without Time.deltaTime, movement speed would change based on how fast frames are updated.