- Home /
2D Box Colliders Overlapping On Collision
I am attempting to make a 2D platformer in Unity, but have run into a problem with the physics. When my character jumps and lands, its Box Collider 2D overlaps with the ground's Box Collider 2D before being pushed out, creating an unwanted bounce effect. The amount of frames this overlapping occurs in depends on the velocity of the character, but I am unable to get rid of it entirely. I have seen similar issues reported when researching this problem, but I cannot find a concrete answer that works for me.
I've tried setting the Collision Detection of Rigibody 2Ds to "continuous", and adjusting several of the Physics2D Settings, including "Min Penetration for Penalty" and "Baumgarte Scale". Neither of these work properly. I have noticed that having the Physics2D settings set to their defaults gets rid of this problem for the most part, but causes the Box Collider 2Ds to have noticeable gaps between them on collision.
I am unsure of how to fix this problem. I want the character to touch the ground without overlapping it. Any help is appreciated.
EDIT: I have yet to find a solution to this problem all this time later, and so I'm bumping this old thread. I've tried changing all sorts of physics settings, code, etc., but nothing is working for me.
hi dude, i was wondering if you found the answer to this problem ' cause i'm having exactly the same problem and the player speed is not too high... thanks!!!
Answer by Raimi · Jun 12, 2017 at 05:57 PM
Object.GetComponent<RigidBody2D>().isKinemetic = true;
Please explain why this would be helpful By the way, I don't believe this would solve the issue
Answer by davidjohn123 · Sep 03, 2016 at 07:42 AM
limit z rotation of rigibody2d. for ground collision issue. you can use layers. i will recommend you to watch this video https://www.youtube.com/watch?v=flGbKSSUY0o&list=PLiyfvmtjWC_XmdYfXm2i1AQ3lKrEPgc9-∈dex=2
I already have "Freeze Rotation" checked for Z.
I switched to the Physics2D.IsTouchingLayers method for ground detection as seen in the video. This seemed to di$$anonymous$$ish the amount of frames the player is stuck in the ground (I haven't seen it visibly for more than 1 frame). However, the player is still gradually pushed away from the ground before reaching its final landing position, and this is very noticeable as I am working with 8-bit-styled sprites.
If there is a way to just get rid of this bouncing effect altogether, with the player just remaining still once in contact with the ground, that's what I'd like to use.
yes make a physicsmaterial2D and raise the friction,then add this material to the colliders of ground..and sorry for late reply
But I don't want any friction on the various GameObjects in the scene.
I already have a default Physics$$anonymous$$aterial2D set with no friction or bounciness. I attempted to make 2 separate Physics$$anonymous$$aterial2Ds - one with friction for the ground and one with no friction for the player - but this didn't solve the problem.
Answer by patosalas · Jun 12, 2017 at 05:39 PM
I´m having exactly the same problem right now, please let us know if you found an answer. I´m still looking for one
Since making this thread, Unity has published a video tutorial series for creating custom 2D platformer physics rather than using Unity's built-in system. I don't fully understand the tutorial, but it basically guides you through making scripts that control the physics directly rather than relying on the built-in system. I'm checked, and this does indeed eli$$anonymous$$ate the overlap problem.
Yes, you are right, I´m already studying how to program physics to avoid problems