2D Object penetrating a 2D polygon collider and getting stuck

Hello gamers!
I am fairly new to Unity, I have a game on the App Store called Paddle Battle (iPad only), I made it using Cocos2D and Swift on Xcode. But I decided to move to Unity since I think it is more mature game development IDE.

What I have
I am trying to make the same game I made, where I have a ball moving at random speed by applying impulse on it at the start, and the Paddle move by touching and drag left and right in arc path. The Paddle here has a 2D polygon collider with physics material attached to it, and the ball has rigid body 2d and circle collider 2D. 2271464--152244--Screen Shot 2015-08-28 at 2.16.02 PM.png

The Issue
My problem is when I move the Paddle quickly with my finger, trying to hit the ball, the ball ends up getting stuck inside of the Paddle collider. I tried to change everything and I read most common physics problems and how to get around it but non of that could solve it.

What I need
I wonder why Cocos2D or SpriteKit have no problems whatsoever in providing this free behavior where I can move the paddle so fast and hit the ball and the ball speeds up by how hard I hit it and move in the relative direction of the impact. How can I have the same behavior in Unity?

I have some images attached showing the problems and my editor settings for both the Paddle and the Ball.

1 Like

any hints on how to fix this issue, please?

The PolygonCollider2D isn’t a single primitive collider, it just generates multiple convex colliders. If you create a situation where the paddle is overlapping the ball then the ball can get stuck between two opposing collider-shapes (Box2D fixtures) that compose the paddle because Box2D solves fixtures individually. See a great video demonstrating this issue here (Collisions Are Resolved One Pair of Bodies at a Time).

You must ensure that you allow Box2D to move the paddle and not set the transform directly else you’re just transporting the object from one position to another, hence the overlaps. You can use MovePosition to move a Rigidbody2D. If you are using forces to move the paddle then you should consider making both the ball and paddle use continuous collision detection.

If the paddle is moving without setting the transform directly, you can use the EdgeCollider2D to create an outline.

1 Like