Character walks over NPC's collider

Hi,

I am currently having issues with my player character walking over an NPC’s capsule collider. I’m not using the Unity built in character controller, but a script with RigidBodies and capsule colliders for both. The NPC has a navmesh agent too, though I have already ruled this out as the problem. I’m sure it has something to do with either the capsule colliders and/or RigidBodies. If my character has a higher mass than the NPC then it doesn’t walk over it but rather pushes it as if it was on ice. Neither object is on any special tags or layers. I can walk up slopes but can’t quite walk up steps (though I haven’t fully tested that yet), walls and other colliders work well with the character it just seems to be this NPC. I was struggling to Google this as I was unsure on what to search and all attempts just pulled up various other problems.

If anyone knows any fixes, has any ideas or has even had this issue themselves please let me know. I am curious as it doesn’t seem to be a common issue. I am also wondering if playing with Unity for the last 19 hours non-stop has anything to do with it. I will try and sleep on this to see if I can come up with any ideas, I will come back and update if I manage to get anywhere with this.

Thanks

If using the built in character controller, the first thing you do is note that it is not rigidbody based but it will affect the transform. It’s based on raycasts.

As it will affect the transform it will fight the rigidbody and you will not get a good result. In addition to this, the navmesh agent is also affecting the transform.

Second thing to note is that it will not give you collision reports or anything unless you have done a .Move or .SimpleMove as this will cause it to raycast.

So you now have 3 things fighting over the same transform. Not good. How about designing it so only one thing has control over your transform at a given time?

The Unity docs do list an example of how to get character controller to push rigidbody.
They also have an example how to make navmesh agents work with root motion or rigidbody or character controller.

All of these require choosing which one at what time, should be moving your transform. It seems to me, you need to think through the desired behaviours before asking what you want help with, because you’re actually asking for help to make something that’s broken, more broken.

You can hack a fix but it will be a band aid in this scenario…

Hi,

I mentioned in my post that I am not using the built in character controller. Only the NPC uses a navmesh agent (I am pretty sure this isn’t causing the issue but will test this further shortly).
I am unsure if the rest of your answer was based upon me using the built in character controller.
I will also give the manual another check on the topics you mentioned as they may still be of use to me anyway.

Thanks

Edit: I just wanted to update after a quick test I was completely wrong, the Nav Mesh Agent is the problem. When I removed the component completely (rather than simply disable during runtime) the issue went away.

Based on this discovery and your answer above, I believe the colliders may be switching between each other (or something like that) and that my character is essentially using the difference between the colliders as if they were steps.

I will have a think and Google and update if I get any further results.

Edit No.2 Solved: After a very quick Google on Nav Mesh Agents and colliders I came across this link https://docs.unity3d.com/Manual/nav-MixingComponents.html which explains that the RigidBody MUST be kinematic else a race condition occurs between the 2 colliders causing issues (I guess the issue I described). After setting the NPCs RigidBody with the Agent attached to isKinematic the issue went away.

I guess this can be marked as solved and archived for anyone else who comes across this issue.

Thanks

2 Likes

The advice is relevant with or without character controller. If it’s agent vs rigidbody, you need to decide who will be authoritative over movement.

The docs (there’s a lot of them about this subject and you’ll be able to search) explain what to do if moving an agent with a rigidbody. There’s a few approaches:

  • disable agent updatePosition and use desiredVelocity to move the rigidbody
  • set rigidbody to kinematic while it moves
  • use navmesh without an agent

In my own game I use the agent’s desired velocity to hint to me where the navigation system wants to go but drive all physics with my own custom rigidbody controller. The agent has no control over positions but I have to do more work. That’s my choice, for my situation though.

1 Like