Search Unity

NavMesh Agent Collider issues

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

  1. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    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?
     
    ShmEmad likes this.
  2. Clydey2Times

    Clydey2Times

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

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    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:
    242
    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?
     
    manicorp likes this.
  5. Yandalf

    Yandalf

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

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    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:
    491
    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:
    242
    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:
    491
    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;
     
  14. BeestGames

    BeestGames

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

    manicorp

    Joined:
    Dec 2, 2019
    Posts:
    1
    Actually for all Unity Leaner who are using this course on Udemy, need to update their Player C# Script.

    1. add "using UnityEngine.AI" to Player.cs;
    2. add
      " [SerializeField]
      private NavMeshAgent _navMeshAgent;" to the Player Class.
    3. add "transform.position = _navMeshAgent.nextPosition;" to Update() method.
    4. assign your Agent Component to its blank field on Unity Inspector.
    then you have a player with boundaries on the Baked Map.
    good luck! Happy Learning.
     
  16. Mohammad_021

    Mohammad_021

    Joined:
    Jan 22, 2019
    Posts:
    3
    Thanks all of you guys
     
  17. SvenNet

    SvenNet

    Joined:
    Mar 13, 2020
    Posts:
    1
    I have the exact same problem with the exact same course. Adding the code as suggested above is not working like it should. When i add the suggested code, the navigation is not smooth any more, it seems that the CharacterController is conflicting with the NavMeshAgent.
    When you have the course and look to the video 208 very closely you see at timestamp 5:18 that the instructor is also suffering the same issue. Is the NavMeshAgent and the CharacterController meant to work together on a player object?
     
    Last edited: Jul 13, 2020
  18. ownsoftnetsolutions

    ownsoftnetsolutions

    Joined:
    Jul 16, 2020
    Posts:
    1
    I have the very same issue. I added the suggested code and it worked.
    I had to set the Area Mask of the Nav Mesh to Walkable though
     
    Last edited: Jul 16, 2020
  19. CarnivorousV

    CarnivorousV

    Joined:
    Dec 20, 2019
    Posts:
    1
    Hi!, I read on the tutorial the solution to this (I got it from a spanish version of the same Tutorial):

    "Edit>Project Settings>Physics>Auto Sync Transforms"
     
  20. Gibs_

    Gibs_

    Joined:
    Apr 17, 2020
    Posts:
    1
    This worked perfectly for me, no need to add anything to the scripts. Thanks!
     
  21. sokolosk

    sokolosk

    Joined:
    Aug 6, 2020
    Posts:
    1
    This work perfectly to me, thanks