Character gets stuck in the wall collider

saboehnke

New member
I know this question was addressed in this post. But the difference in my case is I am creating dynamic characters. I have made a change so that the capsule collider that is added to the character uses the SkinnedMeshRenderer's bounds to determine the center and height of the capsule collider. This way it correctly matches the size of the character. This results in issues where my characters gets stuck as soon as they run into a wall. It happens the exact same way as the previous post mentions. There is only one collider on the character (the capsule collider) and it is not clipping inside the wall or anything weird like that. I have also tried setting the AllowRootMotionPosition and AllowRootMotionRotation to false but it changes nothing. Any ideas?

ezgif-2-8c8820b2a6.gif

Here is the code I use to setup the character dynamically:

C#:
CharacterBuilder.BuildCharacter(gameObject, new GameObject[1] { playerObj }, true,
new RuntimeAnimatorController[1] { playerAnimator.runtimeAnimatorController }, string.Empty, ControllerType,
false, new GameObject[0][], null, false);
CharacterBuilder.BuildCharacterComponents(gameObject, false, false, null, null, false, true, true, playerAnimator.isHuman, false, false);
var characterLocomotion = gameObject.GetComponent<UltimateCharacterLocomotion>();
MakeRagdoll(playerObj);
AddAbilities(characterLocomotion);

var camera = CameraUtility.FindCamera(gameObject);
if (camera != null)
{
var cameraController = camera.GetComponent<CameraController>();
if (cameraController != null)
{
cameraController.Character = gameObject;
}
}

And this is the code I've changed to set the capsule collider based on the mesh:
C#:
 var meshrenderer = character.GetComponentInChildren<SkinnedMeshRenderer>();
capsuleCollider.height = meshrenderer.bounds.size.y;
capsuleCollider.center = meshrenderer.bounds.center;
capsuleCollider.radius = 0.4f;

I have tried multiple different center and height values but they end up with the character being partially in the floor or the collider height just doesn't make sense.
 
Last edited:
Moving to the Ultimate Character Controller forum.

This looks like it's different from the thread that you linked to as that one is related to extruding objects which I'm assuming you don't have in your screenshot. If you don't make the change that you mentioned does it work correctly?
 
No. This issue persists for me whether I make the change to the capsule collider properties or not. You are correct, I have no protrusions from my walls. It is a flat surface on which I have tried both a mesh collider and a box collider. Both result in this issue.
 
I'll have to check when I can get the demo scene back up. But should it matter? It's a different situation. I'm creating them dynamically but using the functions I mentioned before. I need to be able to dynamically setup these characters and have the capsule collider size make sense without getting stuck to walls.
 
It shouldn't matter but I need a way to reproduce it in order to further tell what is going on. The UMA integration also creates the character at runtime and I don't have the same issue.
 
I'm not able to get you a demo project with my stuff in it. It is a project for work and I have models being pulled from playfab. I just have the capsule collider taking the shape of the character like you have in your demo.

1702399008540.png
I did notice that in the demo scene if you add a Plane primitive to the scene, turn it so it is perpendicular to the ground, and you walk into the back side of it (no idea why the back side...) the character gets stuck.
 
Unity's plane has normals facing one way so that's why it gets stuck when you don't have a two sided plane. If you can tell me how to reproduce the issue I'll be able to take a closer look. If you want to debug it yourself I'd start by looking at CharacterLocomotion.DetectCollisions and see where it is getting stuck.
 
Somehow it works if I turn off the capsule collider component. The character can walk up to a wall, collide with it, and not get stuck. The character has no other colliders.
 
If the character is avoiding the wall there has to be other colliders. The CharacterLocomotion only detects collision against the enabled colliders.
 
I can't really tell you what was going on...but it just kind of started working. I just have the capsule collider on the character and it seems to be working after just changing the capsule collider's height to the mesh renderer's bounds.y value as well as changing the center of the capsule collider to a new Vector3(0, meshrenderer.bounds.center.y, 0);
Seems to be fine now!
 
Top