Search Unity

Question NavMeshAgent.SetDestination and TimeScale more than 1.

Discussion in 'Navigation' started by Musturd99, Mar 16, 2023.

  1. Musturd99

    Musturd99

    Joined:
    Sep 2, 2022
    Posts:
    2
    I notice that when using SetDestination method when timescale is more than 1, SetDestination seems not working as usual? The SetDestination method returns true which means the path is valid, but characters still remains at the previous position, no path was assigned, and the bool of hasPath and pathPending are both false.
    I also noticed that in Unity Scripting API: Note that the path may not become available until after a few frames later. While the path is being computed, pathPending will be true. If a valid path becomes available then the agent will resume movement.
    Is this problem occurred because there is no time for navmesh agent to calculate the path?
    Does anyone have the same issue too? Plz help and discuss.
     
  2. Musturd99

    Musturd99

    Joined:
    Sep 2, 2022
    Posts:
    2
    OH I just noticed that even not in speed-up timescale, some characters still stayed at the same position. Here's my code, but the "died" characters is fewer:
    public class GoToRegion
    {
    public void EnterState(Person person)
    {
    person._agent.speed = UnityEngine.Random.Range(1.5f, 2.2f);
    person.stateEnum = StateEnum.GoToRegion;
    person._agent.ResetPath();
    Region[] regions= PeopleFlowManager.Instance.regions;
    person._targetRegion = regions.Where(p => p != person.region).ToArray()[UnityEngine.Random.Range(0, regions.Length - 1)];
    person.SetDestination(person._targetRegion.polygon.PickRandomPointInPolygon());
    }
    }

    public class Person
    {
    public void SetDestination(Vector3 target)
    {
    NavMeshHit hit;
    NavMesh.SamplePosition(target, out hit, 10, NavMesh.AllAreas);
    _targetPos = hit.position;
    _agent.SetDestination(_targetPos);
    }

    public IState State
    {
    get
    {
    return _state;
    }
    set
    {
    _state = value;
    _state.EnterState(this);
    }
    }
    }