# How to make sure an object NEVER passes through an edge collider (2D)?

In my top down perspective game, I have a ball that bounces off of walls. The ball should behave in a way where it will always bounce off in a 90 degree angle. The ball can only move up, down, left and right and the walls are slanted so that they should always (theoretically) bounce a ball up, down, left or right.

On the ball object, I have a small circle collider 2D and a Rigidbody 2D attached, the walls have a single edge collider 2D attached. Approximately one time out of twelve times, the ball will simply pass through the edge collider, so it's not consistent.

How can I make sure that the ball always registers the collision?

Here's my setup:

The script I use to move the ball:

void Update () {
switch (direction)
{
case 'u':
transform.Translate(0f, ballSpeed * Time.deltaTime, 0f);
break;
case 'd':
transform.Translate(0f, ballSpeed * -1 * Time.deltaTime, 0f);
break;
case 'l':
transform.Translate(ballSpeed * -1 * Time.deltaTime, 0f, 0f);
break;
case 'r':
transform.Translate(ballSpeed * Time.deltaTime, 0f, 0f);
break;
}
}

- every wall is it's own object with it's own edge collider.
- the ball always hits the center of the wall because I center the ball object using the center of the wall it touches. Note: I had issues with the ball passing through walls even before I implemented the centering.

• Looks like you're making the common error of moving the transform instead of the rigidbody when you want physics behaviour. See this answer for more details on why that causes problems. Commented Oct 5, 2018 at 11:45
• Can you post a screen of your scene? Commented Oct 6, 2018 at 13:58
• It also looks like your circle has a very small radius, which could cause precision errors. What happens if you significantly increase the radius? Commented Oct 6, 2018 at 14:45
• @EdMarty I think I already tried that, and it didn't really help. The ball would still sometimes just pass through the wall.
– user97936
Commented Oct 8, 2018 at 8:54