- Home /
Character controller getting stuck underneath of ramps
In my game, I have a character controller, which works fine for the most part, and is perfect aside from one quirk. The issue only seems to come in when the top of the character controller is touching the underside of a ramp, and at which point the player will not be able to move except in (roughly) the opposite direction of the wall's face.
To demonstrate the issue, I'll use some screenshots and captions.
In this picture, the player is colliding with the ramp, and is unable to move unless they attempt to move away from the ramp. In most other games, which I intend to replicate, the player can still move to the left and right, but obviously not forwards further into the wall. In my case, the character controller seems to get closer to the ground and will not budge either left or right.
I did some testing, and found out that the player isn't actually applying ANY force to the slopes in this case, which seems to be an issue with the isGrounded() boolean of character controllers. Perhaps this is why going up ramps instead of underneath them does not produce the same errors. I can demonstrate this here:
As you can see in this picture, Before: (velocity), the velocity before the wall pushes back against the player, Force applied: vector3(), the normal * the amount of force applied, and after: (velocity). The odd thing is that the player is not applying any force to the ramp on the Z axis, which is why the player can accelerate against this wall?
Most importantly I found out that the velocity downwards into the ground is probably what is causing most of the issues, but I do not know WHY, nor how, or even what to do about it.
Edit: Due to the fact that the capsule collider has the sloped top, when they collide with a wall, the highest or lowest point of the capsule collider can not get any closer to the walls/floor/ceiling.
Unfortunately, this means that unless the player moves exactly parallel to or back away from the wall/ceiling / wall/floor combination, they will get stuck.
Now the question is then, how do you make the character controller interact with collidable objects as if they had a cylinder instead of capsule collider? I know you cannot change the collider type on character controllers, but is there any way to stop the player from moving into a space where a theoretical cylinder would end up at?
There are a lot of weird things with this. First, a CharacterController or rigidbody cannot apply any force to a kinematic rigidbody nor to a static collider. How do you even get the vector you are displaying?
Second, do you use $$anonymous$$ove, Simple$$anonymous$$ove, or (that would be bad) Translate to Livraison the character?
Third, have you tried playing around with the various character controller settings? (Slope, etc)
A simple way to fix this would be to add invisible walls under ramps.
Another would be to add a raycast to prevent mouvements that would get the character stuck, but that might cause more problems.
Answer by JasonBennett · Dec 18, 2019 at 05:41 PM
My guess is that this has something to do with the Capsule Collider and its rounded edges. You are essentially getting the head wedged under the ramp so that the only safe direction is backwards.
Try adding a second Box Collider to your player GameObject and position it so that the player has a big blocky head. See if this fixes the problem, and if not, let me know.
I had thought of this, and I really just want the entire player to be a box collider, but that is only an option with rigidbodies. This is a character controller.
You can add a box collider to the Player gameobject. It won't interfere with the Capsule Collider on the Character Controller.
I don't think you can add colliders to a CharacterController like you can for a rigidbody.
Can I simulate the theoretical cylindrical boundries of a collider any way? @ceandros
Your answer
Follow this Question
Related Questions
Objects stuck dragging across floor 1 Answer
Player gets stuck into object after collision 2 Answers
Trying To Make Burger Builder 1 Answer
Car collision impact with object 1 Answer
Physics or Character Controller? 1 Answer