How do I get velocity from a collision?

I am simply trying to get the velocity that an object collides with, so that it can inherit that velocity.
I am new to scripting.

Basically I have a ball and two paddles (imagine something 2D like pong with similar graphics but you can move closer and farther away). If the player charges towards the ball while the paddle is moving in, the ball will pass right through it and not bounce off. This causes the ball to slow down to a crawl.

If there is an easier way to do achieve this please let me know.

You can get the relative velocity between the two colliding objects and bounce the ball back by doing this, in the script that controls the ball:

``````void Start()
{
Rigidbody2D rb = GetComponent<Rigidbody2D>();
}

OnCollisionEnter2D(Collision2D collision)
{
Vector2 velocity = collision.relativeVelocity;
rb.velocity = Vector2.Reflect(velocity,Vector2.right/*make this a Vector2 pointing 90 degrees from your paddle surface*/);
}
``````

Also make sure you have a Rigidbody2D on at least the ball and probably both paddles as well, with the appropriate colliders for their shapes. I believe you will need to freeze the rotation and position in all directions of the Rigidbodies. Hopefully this helps!