I’m trying to make a pong like game & I was watching a old tutorial it’s very helpful but the video was so old things have changed from then to now basically what I’m trying to do is if the paddle is moving left or right the ball then needs to bounce in that direction of the paddle movement & if the paddle isn’t moving the ball must go straight here’s what I have but doesn’t seem to work
float ballForce = 200;
private new Rigidbody2D rigidbody2D;
void Start ()
{
rigidbody2D = GetComponent<Ridgidbody2D>();
float randomNumber = Random.Range(0, 2);
if (randomNumber <= 0.5)
{
rigidbody2D.AddForce(new Vector(ballForce, ballForce));
}
else
{
rigidbody2D.AddForce(new Vector2(-ballForce, -ballForce));
}
}
void OnCollisionEnter2D(Collision2D col)
{
Vector3 vel = rigidbody2D.velocity;
vel.y = rigidbody2D.velocity.y / 2 + col.collider.GetComponent<Rigidbody2D>().velocity.y / 3;
rigidbody2D.velocity = vel;
}