Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

NavMesh Agent Collider issues

Discussion in 'Navigation' started by Clydey2Times, Apr 16, 2019.

  1. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    175
    I'm having an issue with my player gameobject leaving the navmesh collider once I attempt to go outside the navmesh.

    Basically, I have a character controller and a navmesh agent on a capsule. The collider for the navmesh agent stays within the bounds of the navmesh, but the gameobject it's attached to simply leaves the navmesh collider and continues moving outside the navmesh.

    Any idea what is causing that to happen?
     
  2. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    175
    Bump. Anyone?
     
  3. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    What's happening is that both the NavMeshAgent and the CharacterController try to move your character.
    Only use one or the other, or disable the actual movement on either of them.
    If you want to create character movement by clicking somewhere and having your character move there, use the NavMeshAgent. If you instead want to control your character directly with wasd keys or thumbsticks etc, use the Character Controller.
     
  4. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    175
    The problem is I'm following a tutorial and the instructor seems to be getting this to work fine, and I can't for the life of me figure out how. I'm using a more recent version of Unity, but I can't imagine that's the problem here?
     
  5. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    Link the tutorial, please.
     
  6. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    175
    I would, but it's a paid course on Udemy. He's moving the character via the character controller Move() method (and I'm following along). I can't see any difference between what he's doing and what I'm doing, so I'm at a loss.
     
  7. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    And you're certain he's putting a NavMeshAgent on his character as well? If he does all movement through his controller, the Agent would be unnecessary.
    He might actually have turned off the components somewhere, either directly in the inspector or through code. Check if you're not missing anything there. If not, just throw the Agent away for now.
     
  8. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    175
    He's using a level mesh that doesn't have any boundaries. It's just a floor collider. I think he's just using it to demonstrate the navmesh system (I've never used it for anything besides enemies before). It's not really impacting my progress on the course, but it's just one of those things that is bugging me. I want to understand what I'm doing wrong.

    Here's a screenshot of the inspector for his player:

    navmeshinstructor.png

    And here's mine:

    navmeshmine.jpg

    I can't see any relevant difference.
     
  9. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    Yeah, interesting it isn't causing issues for him...
     
  10. BeestGames

    BeestGames

    Joined:
    Oct 6, 2019
    Posts:
    14
    I have the exact same problem with the exact same course. All the settings are identical, and yet my player leaves the Nav Mesh Agent and falls into the floor. I'm attaching a small video here.
     

    Attached Files:

  11. BeestGames

    BeestGames

    Joined:
    Oct 6, 2019
    Posts:
    14
  12. IceCole

    IceCole

    Joined:
    Oct 12, 2019
    Posts:
    1
    Ditto. I'm doing the same course (Via Humble Bundle. I suspect this particular lesson was recycled from a Udemy course he did.) I've quadruple checked his settings vs mine. I've checked the scripting for all of the movement, going through all the videos multiple times just to be sure nothing was missing. So far as I can tell, everything matches.

    The course actually says that without the Nav Mesh Agent, you'll fall off if you walk outside the mesh. Which is true. I fall off without it. According to the video, the whole point of putting said agent on the player is to keep that from happening. The problem, of course being, it happens with it too.

    So we're here with two opposing ideas about the way the Nav Mesh Agent works and both ideas appear to be wrong.

    For those of you having this issue with the Humble Bundle course, I just sent a message to Johnathan directly. (If you guys want to do the same, there's a link to the community channels at the bottom of the main course page.) Hopefully I'll hear back from him. Either way, I'll pursue this issue with GameDevHQ until I get an answer. I'll try to post that answer here, if no one beats me to it.

    In the mean time, good luck.
     
  13. Mikee_Sider

    Mikee_Sider

    Joined:
    Nov 8, 2019
    Posts:
    1
    Just add this line of code to player update and it should work

    transform.position = _navMeshAgent.nextPosition;
     
    DarkSphere and BeestGames like this.
  14. BeestGames

    BeestGames

    Joined:
    Oct 6, 2019
    Posts:
    14
    Thank you. It worked.