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