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.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
The
inDirection
should be the velocity of your ball and theinNormal
should be the unit vector that is perpendicular to your wall.Try putting this in your ball object:
NOTE: I cannot currently test that code, so it may need tweaking in terms of the names of things.
Vector2 Reflect(Vector2 inDirection, Vector2 inNormal)
:inDirection
: black arrowinNormal
: red arrowreturn output
: green arrow