- Home /
2D Smooth Collision, Prevent Player from Clipping Through Wall
I'm using the new 2D features found in Unity 4.3 and my character sprite is using a Polygon collider and Rigidbody2D and my wall is using a Box Collider.
When moving into a wall, the character 'clips' through slightly as if it is trying to force its way into the wall pushes it back so obviously this isn't very smooth. Also, if enough force is applied from the character, it is possible to move the character sprite entirely through the wall itself.
I am not using any code to handle collisions, just the colliders and rigidbody.
Can anyone offer any insight as to how to make this look smoother? For example, stopping the player from moving any further if they are next to the wall?
Thanks
Hey. I have a simmilar problem with my rigidbodies. I tried everything in the inspector and making new physics material. I tried raycasts but that failed in other aspects. Did you manage to controll this bounciness somehow?
Answer by Spinnernicholas · Nov 26, 2013 at 11:31 PM
There are 2 properties of rigidbodies that you can change for smoother effect.
Rigidbody2D.collisionDetectionMode
and
Rigidbody2D.interpolation
See Documentation.
I've tried messing about with these settings in the Inspector, but they don't seem to do anything visibly different. Any suggestions?
The next step is to modify the Physics$$anonymous$$aterial2D of the player and other rigidbodys.
Try setting bounciness to 0.
Answer by GDFenna · Jun 29, 2014 at 07:51 PM
thanks spinner this smoothed my 2D collider collisions
rigidbody2D.collisionDetectionMode = CollisionDetectionMode2D.Continuous; rigidbody2D.interpolation = RigidbodyInterpolation2D.Extrapolate;