Now it is just standing still.
- User
Now it is just standing still.
- Assistant
Can you provide more context or specify what "it" refers to? I would be happy to help if you give me a bit more information.
- User
using UnityEngine; using UnityEngine.AI;
public class AIPatrolAndFollow : MonoBehaviour { public Transform player; // Player's Transform public GameObject patrolTriggerObject; // GameObject that triggers patrol mode public float wanderRadius = 20f; // Increased radius for random wandering public float wanderTimer = 5f; // Time interval for changing destination
- Assistant
It seems like you've provided the code for an AI behavior script using Unity, which allows an AI agent to either patrol randomly or follow a player using Unity's
NavMeshAgent. The AI toggles its behavior between following the player and patrolling based on user input or collision with a specified object. - User
Make it so you get rid of the V pressing, and make it so it patrols randomly around the place. And not getting stuck. But when the player is not in collision with the cube thing, it chases the player. Otherwise it will patrol randomly.
- Assistant
- User
It works, but the AI just stands still. Make it work properly.
- Assistant
- User
Assets\source\source\Materials\AIFollower.cs(86,29): error CS0165: Use of unassigned local variable 'navHit'
- Assistant
The error message indicates that there might be a situation in the
RandomNavSpheremethod where thenavHitvariable is being used before it has been assigned a value. This can occur if no valid point on the NavMesh is found after several attempts, leavingnavHituninitialized.To address this issue, you need to make sure
navHitis always initialized before it is accessed. One simple way to handle this is to set a default value fornavHitbefore the loop starts, or assign it within a conditional that ensures it's only used when valid.Here’s how you can modify the method to prevent this error:
- User
Not working. Fix everything.
- Assistant
- User
Make him faster.
- Assistant