I recently start learning unity and for my first game i choose pong and well the game is playable but have a logical problem with ball and it is when it hit the sidewalls it doesn’t matter the angle of hit,it always come back with same 45 degree angle for example when ball hit with 2 degree it return in 45 and ruin game and predictable
this is the function
any help?
private void wayBall(Collision2D collision, int x)
{
float a = transform.position.y - collision.gameObject.transform.position.y;
float b = collision.collider.bounds.size.y;
float y = a / b;
ballRb.velocity = new Vector2(x, y) * moveSpeed;
Debug.Log(x);
Debug.Log(y);
Debug.Log(moveSpeed);
}
I tried use gemeni and copilot but their code were worst than this
Parsa Ghost is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.