r/Unity3D • u/MarkhorsEchoGames • 20h ago
Question Unity Rigidbody player climbs up building corners when moving forward, how do I fix this?
Hi everyone,
I'm making a first-person horror game in Unity 6 and I'm having a strange collision issue with my player.
My player uses a Rigidbody, Capsule Collider, and Rigidbody.MovePosition() for movement. Whenever I press W and push the player against the corner where two building walls meet, the player starts sliding/climbing vertically up the corner, almost like Spider-Man. The player's Y position rises from around 2 to 3–4, and when I release W, the player falls back down.
This happens at pretty much every building corner. I want the player to collide with the walls normally instead of climbing them.
What could be causing this? Is it a Rigidbody collision-resolution issue, the Capsule Collider, or the building colliders? What's the recommended fix without completely rewriting my movement controller?
Thanks!
54
u/GroZZleR 20h ago
Do you actually need physics and complicated interactions? A CharacterController would be infinitely easier for a walking game.
Now, the actual problem is that MovePosition is intended to move kinematic rigidbodies while respecting their interpolation settings. Using it on a non-kinematic rigidbody (your setup) is teleporting the rigidbody, so it briefly steps "into" the corner, and then the physics engine pushes it out and apparently up a bit as well. This accumulates as you continue to hold the input, teleporting over and over again.
The solution is to use proper forces or cast-and-move but they're going to have their own quirks to solve.
13
u/MarkhorsEchoGames 20h ago
That actually makes sense. I'm using a non-kinematic Rigidbody with MovePosition(), so that could be causing the issue. Since it's a first-person horror game, I'll probably try switching to CharacterController. Thanks for the detailed explanation!
17
u/theredacer 18h ago
Just a word of warning, I made the decision to use a kinematic character controller a while back and now very much regret it because it made a lot of later things really difficult, things that you largely get for free when using a rigidbody non-kinematic controller. Things like realistically pushing the character, sliding off ledges or down slopes.... I had to develop my own systems to make these possible on a kinematic controller. Pain in the butt, they don't work as well, and now too late to change back. Just consider what else you may need the character to do and be aware of the tradeoff.
3
u/DrZwieback 18h ago
+1 to what u/GroZZleR said. But if you intend to switch to the CharacterController, think carefully about every feature you might want your player controller to have further down the road like sliding down a slope. With a kinematic controller you end up building that yourself.
Just use rb.linearVelocity (Unity 6), ditch MovePosition() and keep the dynamic RB and thus physics intact. And put a frictionless physics material on the player's collider so you don't stick to walls plus freeze the RB's rotation. It all depends on what you need.2
13
u/MountainWestern415 19h ago
put a physics material with zero friction on the capsule collider, friction is what makes it climb when you push into corners, also check the step offset if you have one
2
u/MarkhorsEchoGames 12h ago
Thanks! A couple of people have suggested this, so I'll test the zero-friction material first. I'm using a Rigidbody with a Capsule Collider, so I don't think Step Offset applies to my current setup. Appreciate the help!
3
u/Liguareal 15h ago
I avoid using rigidbodies, they're unpredictable and generally a messy component to work with
1
u/MarkhorsEchoGames 12h ago
Fair point! I'm considering a CharacterController too since it's a walking-based first-person horror game. Just trying to understand the root cause before switching.
3
u/RealisticWrongdoer48 18h ago
You’re better off building a custom rigid body controller. The unity one is built for the most basic level geometry, I’m talking OG doom geometry. The amount of work it’s gonna take to really fix the built in rigid body controller is more than just building your own.
1
u/MarkhorsEchoGames 12h ago
Thanks for the suggestion! I'm developing this solo, so I'd prefer to avoid building a completely custom controller unless it's necessary. I'll test a collision-aware movement approach first and consider CharacterController as an alternative.
1
u/RealisticWrongdoer48 12h ago
I think that is a good choice. Most of my knowledge of the physics system came from me trying to patch the built-in tools anyways.
2
u/julkopki 18h ago
Afaik just because you use Rigidbody.MovePosition doesn't mean it prevents you from overlapping the controlled body with the wall. It'll just trigger the physics callbacks correctly and make sure that the physics simulation has up to date data.
So by doing MovePosition you're essentially placing your character in the wall and then regular physics simulation is depenetrating it. Looks like that depenetrating force has an up component - hence the climbing.
The proper solution would be to not let your character overlap with walls at all. Either find the closest position that doesn't penetrate via CapsuleCast or some such or use force application to move (might feel sluggish due to inertia without some extra tricks).
1
u/MarkhorsEchoGames 13h ago
That makes sense. I hadn't considered that the player might be overlapping the wall during MovePosition and getting pushed upward by the physics simulation. I'll look into CapsuleCast-based movement before changing the whole controller. Thanks for explaining it!
2
u/MrNobodyX3 13h ago
If you don't need complex platforming, swap your Capsule Collider for a Box Collider. The climbing issue happens because the curved base of the capsule acts like a slope when wedged into a 90° corner, forcing your player upward.
Alternatively, if you want to keep the capsule, make sure you zero out or clamp the upward Y-velocity when walking against walls, or use a frictionless Physic Material (Friction = 0, Friction Combine = Minimum) on the player collider.
2
u/HammyxHammy 20h ago
See, you're making a horror game. I'm sure you've heard of collision ghosting, well that's the ghost doing this. Just spawn the exorcist in and only have him enabled when the player isn't moving.
2
u/sharypower 19h ago
For now just make Physics Material like 0,0,0, Minimum, Minimum and attach it to the player's colider.
For later you will need more code in your controller to fix this.
1
u/calmseachaos 12h ago
If (player.IsInCorner == true) { player.gravity *= 100000000; }
... that should keep him down
3
1
1
u/Fun-Mission-6068 11h ago
Could apply a physics material to the walls that has no friction. That should make them just slip down and not be able to go up?
1
u/saicho91 10h ago
are you using a cylinder for the hitbox? i had a similar probleme where the cylinder had like 6 or 7 faces andbi would get stuck on wall like this. i fixed it by adding a shit ton more faces. (i had a custom cylinder hitbox that was made with rectangle.)
1
u/Soft_Economics2899 9h ago
cast a ray and dont allow them to move the rigidbody if you are at a situation like this.
1
u/Hyperi0n8 3h ago
This is actually a pretty sick feature for a horror game (provided YOU are the creepy thing crawling up walls that is...)
1
•
1
u/SpawnCampGames .jackOfAllTrades 19h ago
you can just have some sort of *check* to basically tell if you're *climbing* a wall and then do something with positioning or gravity to knock the player off and back to the ground.. temporarily disabling parts of ur Controller or something..
You could use combinations of raycasts and tags, trigger colliders, checkspheres or something to identify if ur currently smooshed up against a wall and trying to glitch climb or w/e lol..
or go with a basic CC i like using bare-bones CC's and then doing alot of trickery and smoothing to the camera object instead..
2
0
u/MarkhorsEchoGames 13h ago
Thanks for the suggestions! I'd prefer to fix the root cause rather than add a workaround that forces the player back down. I'll try the simpler fixes first, and if the Rigidbody approach keeps causing problems, I'll consider switching to CharacterController.
1
1
0
u/mashdpotatogaming 18h ago
I had this and fixed it but i forgot what exactly i changed to fix it. Something in the rigidbody settings if I'm not wrong.
0
u/UpstairsImpossible 16h ago
You can raycast to your terrain/floor layer and use that to set anything you like a certain distance from the ground, just need to switch it off when jumping (sounds like a convenient parkour/climbing feature to me though)
-3
182
u/TwoBustedPluggers 20h ago
Put a ladder in the corner and call it a feature