Breakout-Clone: How to get a 100% Physical Reflection ?

Hi there,

i’ve started to programm on a more simple game.
A Breakout-Clone, to get myself familiar with C#.
(However, it’s not a problem with C# i have here)

If anybody doesn’t know what Breakout is,
look here for example: http://www.filemaster.de/spiele/smashing/smashing.php (not my work!)

My Problem is:
I’m using the inbuilt physics engine,
and if my ball is hitting the wall,
the angle is getting smaller and smaller with each hit to the wall.
Realistic, maybe, but in such games,
the reflection has to be like if a ray of light would be reflected on a mirror.
So if the angle of impact is, for example,
60 degrees in, then the angle of the ball getting out should also be 60 degrees.
But as mentioned, it gets smaller and smaller with each wall hit.

I already turned of gravity, and made all physics material bouncy.

I also control via script that there is no movement in the y-direction (Because it’s like topdown view and i don’t want the ball to jump over the walls)

For completeness the complete ball control code:

	void LateUpdate() 
    {
        Vector3 newSpeed;
        newSpeed = rigidbody.velocity.normalized;
        newSpeed *= speed;
        
        // Ensure that the ball never goes vertical only - thus would never return to the player
        if (Mathf.Abs(newSpeed.x) < minimumHorizontalSpeed)
        {
            if (newSpeed.x <= 0F)
                newSpeed.x -= 1;
            else if (newSpeed.x > 0F)
                newSpeed.x += 1;
        }

        // no 3d for the poor ball
        newSpeed.y = 0;

        // assign the new Velocity
        rigidbody.velocity = newSpeed;
	}

So basically, this script ensures that the ball always moves with the same speed and never stops.
It also ensures that it never moves vertically only
(because the player pad is at the right side of the screen)

Problem is:
I cannot simply calculate impacts for myself,
because there will also be convex&concarve objects … the player-pad for example has such a form to give the player the ability to control in which direction he wants to push the ball when he comes back to him.

Best solution would be to alter anything in the physics itself … anyone has an idea ?

Thanks in advance,
David

  • Create a new physics material, don’t just use the supplied bouncy. Get rid of all friction.
  • Raise the angular momentum limit in the project’s physics settings.

The delta from expected you’re experiencing is likely because of those two factors.

In terms of user control of the ball via the paddle, I would just let the physics engine generate that as well. Use a curved collider. A sphere collider squished along the Y would pull off the english illusion famously.

Hi,
the custom material worked almost perfectly for me, thank you very much :slight_smile:

only little problem now is that the spherical collider cannot be resized at will …
meaning it always is a perfectly round sphere,
meaning that the largest value of the scale is used to determine the form.

Example:
if its object has a scale of , let’s say (5,x,x) then it has no effect what ever value “x” is, as long as it is smaller than 5.

So it’s unfortunately not possible to make a sphere which is scaled only at one axis.
But that’s okay, i just made a seperate Collider Gameobject, moved it a bit behind it, and it works fine for now.
(will get difficult when i add a powerup which makes the pad longer, as for now, its width equals its height)

kind regards,
David