Vector3.Dot() for collision bounce back

Hi everyone,
Im new to the community but not to Unity. I’ve made several little games before and know my way around the engine. Im currently making an Air Hockey game in JavaScript and I am having some issues with the puck bouncing back off the edges of the table. I’m trying to accomplish this without using rigidbody physics as it seems to be unreliable at faster speeds.
Currently I have four boxes set up, one on each edge of the table spanning that edges length. Each box check to see when the puck is within range of it and then calls this function which, I thought, would return the new direction the puck should be traveling. But it isn’t. Any help or suggestions would be greatly appreciated. Thanks :slight_smile:

function CompareAngle(other:Transform)
{
        var bumpBackDirct:Vector3;

	var forward = this.transform.TransformDirection(Vector3.forward);
	var toOther = other.position - this.transform.position;
	var impactAngle = Vector3.Dot(forward, toOther);
	print(impactAngle);
	
	var puckCurDir = puckCntrlScript.GetMoveDirct(); //puck's current direction
	
	var returnDirct:Vector3;
	
	if(isFrontBumper)
	{
		bumpBackDirct = this.transform.forward;
		returnDirct = (bumpBackDirct * impactAngle)+ Vector3(puckCurDir.x,0,0);
	}
	
	else if(isBackBumper)
	{
		bumpBackDirct = -this.transform.forward;
		returnDirct = (bumpBackDirct * impactAngle)+ Vector3(puckCurDir.x,0,0);
	}
	
	else if(isLeftBumper)
	{
		bumpBackDirct = this.transform.right;
		returnDirct = (bumpBackDirct * impactAngle)+ Vector3(0,0,puckCurDir.z);
	}
	
	else if(isRightBumper)
	{
		bumpBackDirct = -this.transform.right;
		returnDirct = (bumpBackDirct * impactAngle)+ Vector3(0,0,puckCurDir.z);
	}

return returnDirct;
}

the dot product does not give you the angle between 2 vectors. It would give you the cos of the angle if the vectors were normalized!
You should use Vector3.Reflect for this.

Finally, position your sides so that they are ‘pointing’ inward. Say the ‘up’ side of your frame objects is always inward.
Then you would simply reflect your pluck velocity along the colliding side up vector.
You would aslo have to take the negative of this reflected vector.