Hello, I am relatively new to C# and Unity. I have almost managed to complete Pong written in C# , I have implemented a scoring system, AI, (almost) realistic physics for the ball and out of bound areas. But there are two minor issues that I am having trouble with.
The first is the ball, I have coded it so that it bounces off of both rackets perfectly. But when it comes into contact with the north and south boundaries it will just simply glide along on the surface of the boundary and not actually bounce.
else if(other.gameObject.name == "TopBorder")
{
rigidbody.velocity = new Vector3(rigidbody.velocity.x,
rigidbody.velocity.y,
rigidbody.velocity.z * -1.0f);
}
else if(other.gameObject.name == "BottomBorder")
{
rigidbody.velocity = new Vector3(rigidbody.velocity.x,
rigidbody.velocity.y,
rigidbody.velocity.z * 1.0f);
}
With these two bits of code I am trying to make the ball bounce off of the border but it follows the x axis instead of the z and I am not sure why.
Also when the ball goes out of bounds how do I reset it to it’s original position without reloading the scene to keep the player/enemy score?
Thank you in advance!