- Home /
Player Clipping into Wall on collision,Player Clipping into Walls
Hi I'm having issues with my player clipping into a wall.
When I walk into a wall and carry on holding the movement key, the player will slightly clip into the wall and stay there until I release the movement key. Here's an example image:
I've tried to increase the size of the collider on both the player and the wall, but the same issue occurs where there is slight movement towards the wall until the key is released.
Does anyone know how to fix this problem? I only have a rigid body on the player object, and am using the MovePosition function to move the player. I also have Collision Detection set to Continuous on the rigidbody.
Answer by twrabetz · Mar 30, 2020 at 03:00 PM
Based on reading some other answers, it seems that rb.MovePosition could miss collisions in some cases.
You could try adding forces to move instead, using rb.AddForce([vector3 of your position change], ForceMode.VelocityChange).
If you want to simulate a constant velocity while using a force, you can do rb.AddForce( [your position change] - rb.velocity, ForceMode.VelocityChange). This should subtract out the previous velocity, moving you at a constant speed.
If you already have movement set up with forces, you can also try going to the rigidbody of your player object, and change collision detection to "continuous". This is a higher performance cost, but more accurate collision detection.
Answer by Pangaroo7 · Mar 29, 2020 at 12:20 AM
I could be wrong with my answer, as I haven't made any collision detection in awhile, but I think I know the issue.
Is it possible that your player movement is in the Update function? I used Update to move my 2D character in my game, but it was clipping slighting into the tiles I placed when I moved into them.
Try placing the player movement code into void FixedUpdate() instead. That fixed it for me.
$$anonymous$$y movement code is already in the FixedUpdate function as I thought that might have cause the issue. I've followed youtube videos where they don't have this issue so I'm assu$$anonymous$$g this is something to do with my project settings
Your answer
Follow this Question
Related Questions
Player jumping from wall sometimes jump even when not collided with other wall 0 Answers
How to get correct collision when picking up objects and moving them at high speeds near walls? 1 Answer
Player character clipping through box collider 0 Answers
Player object falling through game environment, collision not detected with ground 0 Answers
Smooth Collisions 2D 0 Answers