Hi everyone!
I am creating a similar pong game (yes, another pong) and I am unable to make the rebound. The main problem is to calculate the angle of the rebound and to make the ball move. Currently, the ball move, but to calculate the angle continuously is problem.
Ps: how post the code in better way?
This is my code until this moment:
// detect the ball collision
void OnCollisionEnter(Collision col)
{
float contactPoint = 0;
//if colide with the pads, execute action
if (col.gameObject.name == “Cube1” || col.gameObject.name == “Cube2”)
{
//return the contact point with paddle.
foreach (ContactPoint contact in col.contacts)
{
contactPoint = contact.point.x;
}
BallSpeed(contactPoint);
BallPosition();
//if colide with the walls, execute action
}
if (col.gameObject.name == “rightWall” || col.gameObject.name == “leftWall”)
{
BallPosition();
}
void Update () {
// transform.Translate(eixoX, 0, eixoZ);
//transform.Translate (new Vector3(radius * Mathf.Cos(angle), radius * Mathf.Sin(angle), 0));
transform.Translate(Vector2.left * speed * Time.deltaTime);
transform.eulerAngles = new Vector2(0, angleY);
}