Search Unity

Object(w nav agent and nav obstacle) jump to nearby location when turn on NavAgent

Discussion in 'Navigation' started by Xhitman, Sep 27, 2018.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Code (CSharp):
    1. public void Move(Vector3 point, float stoppingDistance)
    2.     {      
    3.         GetComponent<NavMeshObstacle>().enabled = false;
    4.         navAgent.enabled = true;      
    5.  
    6.         actionMode = RobotActionMode.Move;
    7.         animator.SetBool("RA003", true);
    8.         navAgent.isStopped = false;
    9.         navAgent.destination = point;
    10.         navAgent.stoppingDistance = stoppingDistance;
    11.         destination = point;
    12.         robotOriginalPosition = transform.position;    
    13.     }
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Okay, this is not how to ask a question here. By simply putting up a topic and a snippet of your code we're left to just guess what exactly you need and how we can help you. Please provide a bit of an explanation what you're trying to do here and properly say where and how things are going wrong.
     
  3. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    It jumps if you robot starting location is inside of a navmesh obstacle or if you didn't place your robot close enough to the mesh so it snaps to it. Also... if you have the obstacle carving checked it might be making the start location of your robot unwalkable so it jumps out.
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Yes, that's default behaviour. NavMeshAgents will at all times make sure they are positioned on or above a NavMesh. As soon as the mesh is gone, they find the nearest point and teleport to it with the Warp function.This is something you have to work around.