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.
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.
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?
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.
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.
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:
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.
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.
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?