D
D
Default_Nickname2022-04-09 17:32:57
C++ / C#
Default_Nickname, 2022-04-09 17:32:57

Unity how to calculate the angle of the ball bouncing off the wall?

I'm making a simple 2D pong game (I think everyone knows what it looks like), I need to calculate the angle of the ball's rebound when it hits a wall (or racket), does anyone know the formula?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2022-04-09
@Default_Nickname

if the relative position of the walls is parallel to the coordinate axes (i.e., either a vertical or horizontal obstacle), then when it hits a horizontal wall, the speed along Y changes to the opposite (the sign changes) and does not change along X, but with a horizontal wall, on the contrary, along Y does not change, but X changes the sign to the opposite (multiply by -1)
if the obstacles have an arbitrary angle, then ... you can see the formulas here

F
freeExec, 2022-04-09
@freeExec

https://docs.unity3d.com/ScriptReference/Vector3.R...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question