# Ball Problems!

I am still very new to Unity. I decided to test my knowledge by building a little 3D Pong-type game. I have two problems.

When the ball hits one of the two paddles, I apply a force in the opposite direction. As the ball hits each paddle over time, the ball gets faster and faster, and faster.

Can I limit the speed of the ball?

The bigger problem is when the ball gets too fast, it actually goes straight through the paddle, and the wall behind it. Why is this happening and how can I stop it?

Thanks,

You can use drag to limit speed. The ball goes through things because the physics engine normally moves objects in discrete intervals, so one frame it’s on one side of an object, and the next frame it’s on the other side, with no intersection. You can use continuous collision instead of discrete to avoid that.

–Eric

Thanks Eric5h5, but Continuous didn’t work. It still goes right through the wall. Any other suggestions?

My suggestion is that perhaps somehow the force applied is maintained and each hit it grows.

My suggestion is to with each hit, set the force to 0. Then set the force in the direction you want.

If that works, the ball wont be so fast that it passes thru the paddle.

Continuous does work, it just needs to be used correctly. Namely, you can’t just set the ball to continuous, but must also set any objects that it will interact with to continuous as well.

–Eric

I did what you said and still it doesn’t work. Can a ball get so fast that nothing will work? Here is what I am doing when the ball hits the one paddle:

other.gameObject.rigidbody.velocity = new Vector3(-100,0,0);

I am just trying to understand what happens at extremes. I really appreciate your help.

Thanks again.

Try setting the interpolation to “interpolate” or “extrapolate”

Thanks. Tried both and didn’t work. Clearly the Physics system in Unity is a little broken.

Not really, but it does have limits.

Consider this:

Give teh ball a rigidbody (no gravity) with no collider.

hold the ball’s current position one frame.
Create a SphereCast from the ball’s last position to current position
If it hits you will get a “RaycastHit”
Use the RaycastHit.normal to get the angle of the hit from the current direction of travel.
Add that angle to the other side
calculate the “overage”
get the magnitude of the current velocity
mag = Mathf.Clamp(mag * addmodifier, 0, maxVelocity)
set the velocity to direction.normalized * mag

Huh??? LOL! Thanks BigMisterB but you are far too advanced for me. I just need the ball to hit the wall and not pass through it. This can’t be that difficult? Maybe I should just cap the overall speed of the ball. I just wanted a more detailed explanation of why this isn’t working. Is it my code?