Unity - how to use Vector2.Reflect()

Kaz picture Kaz · Dec 13, 2016 · Viewed 11.2k times · Source

I have looked everywhere including the Unity documentation but cannot seem to find any good examples of how to use Unity's Vector2.Reflect() function. I am trying to use this to control the direction of the ball (in a 2D Breakout game) when it hits a wall. It takes 2 arguments (inDirection, inNormal) but I cannot seem to figure out how to use this. Any help would be appreciated.

Answer

Lincoln Cheng picture Lincoln Cheng · Dec 14, 2016

enter image description here

Vector2 Reflect(Vector2 inDirection, Vector2 inNormal):

inDirection: black arrow

inNormal: red arrow

return output: green arrow