- Home /
Player "teleports" on top of NavMeshAgent collider if the Agent is too close
hey guys,
I'm using the Unity NavMesh on Unity 5.0.1f1 and I have the problem that my player (which is controled by a PlayerController) teleports on top of a NavMeshAgent if the agent is too close to the player. I need the agent (my enemy) to be very close to the player, so the attack hits the player.
If the enemy stands still, the player can not walk on top of it. But if the player stands still and the enemy approch the player then the player is teleporteted on top of the enemy collider, regardless of its height. That happens also when the "Slope Limit" and "Step Offset" in the character controller is 0.
The enemy has a kinemetic rigidbody and a static boxcollider attached. The player has the playercontroller attached.
I've also attached a navmesh agent, for testing, to the player but then I can't jump and run across areas that are marked as "not Walkable" for the enemys.
Do you know how to fix this problem?
i just found a hint how to solve the problem here: http://answers.unity3d.com/questions/515021/are-charactercontrollers-and-navmeshagents-meant-t.html
He says, that setting the
myAgent.updatePosition = false;
myAgent.updateRotation = false;
can fix the problem. But in my tests, the navmeshagent than stays on the spawn point of the player. So I testet, to wrap the navmeshagent to the position of my player with
myAgent.Wrap(transform.position);
That soloutions works kinda. The Player now can jump and enter places that are not in the navmesh but than the navmeshagent snaps to the closest point on the navmesh. I'm thinking of turning of the navmeshagend as soon as the player jumps or leaves the navmesh area, but I don't know if that is the right way.
Answer by florianveltman · May 29, 2015 at 02:23 PM
I have not set up a test but perhaps try attaching a navmesh obstacle to the player character and/or the enemies. The obstacle prevents the agents to move to that location. I guess the agents now just wanna stick to the spot they were at without being pushed around. If the player has a navmesh obstacle component attached to itself, the enemy won't be able to move to litterally the same spot but get close enough.
This is the solution that worked for me. Placing a navmesh obstacle on the same object as the agent is likely to cause issues (colliding with itself), but placing a navmesh obstacle on the player character will stop the climbing problem. For better results, I made the navmesh obstacle a slightly larger radius than the capsule collider on the Player, and I shifted it down by half of the Player's height. This ensures that even if the Player does get up on top of the enemies for whatever reason, the navmesh obstacle is always pushing their heads out of the way to a slightly wider radius than the Player's collider, and so the Player falls back down to the ground.
Answer by Bastoon · Jul 04, 2019 at 09:51 PM
Hi,
I had to remove the RigidBody of the ennemy and it doesnt teleport on top anymore and collision works.
2 years later, for anyone who may stumble upon this frustrating issue, i can confirm that Bastoon's solution works!
Answer by baptistegr · Oct 03, 2018 at 07:54 AM
I have the exact same issue, did you manage to fix it? The player is controlled with a CharacterController, I set the slope limit to 0 and the step offset to 0 too, but when it gets really close from a NavMeshAgent it goes on top of it and continue to walk on his head.
Anyway to fix this?
Answer by ChrisNoGo · Feb 01, 2019 at 10:57 PM
Okay I think I found the source of the problem. I started having this exact same issue, but I also noticed that my NavMesh agent was intersecting with the collider of the gameobject. When I moved the Navmesh agent so that it wasn't touching the collider, I was no longer having my player teleport to the top of it.
Your answer
Follow this Question
Related Questions
Are CharacterControllers and NavMeshAgents meant to work together? If so, how? 2 Answers
Is it possible to detect which area of a navmesh a navmesh agent is on? 1 Answer
"Nav Mesh Agent" messes up simple prototype player-gameobject. What's up with that? 0 Answers
Navmesh Agent Custom Controller 0 Answers
How to make AICharacterController able to walk on walls and ceilings? 0 Answers