Air hockey game - getting puck to keep moving on change of direction

Hello everyone. I’m making an air hockey game and am having trouble getting my puck to keep moving when it hits the side. I’m using

function Update () {

transform.position.x = Mathf.Clamp(transform.position.x,-26.55, 26.5);
transform.position.z = Mathf.Clamp(transform.position.z,-53.9, 53.97);


to detect when the puck hits the side of the table but how do I get it to bounce back?

The easiest way would be to let the unity engine handle it instead of trying to code it yourself. Just attach a rigid body to the puck, and put colliders on the sides.

If you want to code it, you’d have to calculate the speed and direction of the puck, take the difference of the puck movement to the ‘normal’ of the side of the table, stop the puck, rotate 2x that angle around Vector3.up, and send it off with the same velocity.