Search Unity

Setting NavMeshAgent position

Discussion in 'Navigation' started by Shadowing, Jun 19, 2019.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    I'm having a issue where im trying to set the position where a NavMeshAgent starts out at. Right now it doesn't go exactly where I tell it too. Not sure what I'm doing wrong.

    They should spawn where these red capsules are at



    At first I was setting the position using
    Code (csharp):
    1.  transform.position = SpawnStartPosition;
    But I read I can't do that.
    so then I'm trying to use warp

    Code (csharp):
    1.  
    2. m_NavMeshAgent.Warp(SpawnStartPosition);
    3. m_NavMeshAgent.SetDestination(SpawnStartPosition);
    4.  

    Do i need SetDestination to run for a few frames for it to warp into place?
    Looking at the picture I provided. You can see the navMesh is clearly covering this area. so idk why it would move. Unless there are like hidden links and its snapping to a link point.

    Either way how do I solve this issue or get it do what I'm trying to do.
     
  2. ClaudiaTheDev

    ClaudiaTheDev

    Joined:
    Jan 28, 2018
    Posts:
    331
    Could be a stupid question/answer but you should check the following:

    - Are you really using the position of the capsule as SpwanStartPosition?
    - Are the capsules in the game/scene? Perhaps they have a NavMeshAgent or NavMeshObstacle on them and the humans are placed right next to them because they avoid them.
    - Is it perhaps an animation issue? Look at the transforms position, perhaps it is correct but the animation changes the position of the SkinnedMesh.

    You do not need SetDestination when warped and teh agent has to stay there.
     
  3. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    thanks for the response.
    Ya SpawnStartPosition is the transform of the capsule mesh.
    There is no NavMeshAgentor, NavMeshObstacle or collider attached to the capsule mesh.
    I tried removing the capsule mesh and the magic marker component. Asset i use that creates that capsule and it still does it.

    Still doing more test. Seems to be a nav mesh issue