How can i make an object to change directions after hitting a wall?

I have a 2d game where a ball goes from left to right. I want the ball to automatically change directions after hitting a wall but I can’t find a way to do so. Ive try to use the on collision enter function but it is just not working. I just need to find a way to change a variable (the one that controls the direction) after the ball hits the wall.
Everything is in 2d. The ball is a circle and the wall is a square. Both have collides and the ball has a rigidbody.
Thanks in advance.

Hello @raaul.09… This videos show’s exactly what you want: Change direction Hitting Wall

Hope it helps you… :smiley:

This should work:

void OnCollisionEnter2D(Collision2D col)
{
if(coll.gameObject.tag == "Wall")
{
MovementSpeed = -MovementSpeed;
}
}