Re: What's the formula for reflecting an object off a surface?
I'm looking at the code and this is what I understand so far
pardist = Distance of object away from self
PX = When positive, target is right of self and vice versa
PY = When positive, target is below self and vice versa
VX = When positive, target is traveling right relative to self and vv
VY = When positive, target is traveling down relative to self and vv
judgeX = When positive, target is traveling away from self based on X value
judgeY = When positive, target is traveling away from self based on Y value
UV = Hmm... don't really get what this is supposed to do.
Code:
local UV = -((PX*VX) + (PY*VY))/(PX^2 + PY^2);
If velocity relative to both self and target = 0, then UV = 0
If UV = 0, then new velocity of X and Y are also 0
If position of y and velocity of y are not considered (1-D perspective)
When PX*VX = positive, UV goes into negatives, target traveling away from self,
When PX*VX = negative, UV becomes positive, and target is traveling towards self (ready to be reflected)
As VX increases, UV also increases proportionally and vice versa
Given that VX remains constant (constant X-coordinate movement),
as PX gets closer to 0 (target gets closer to self X-wise), UV decreases.
Purpose of UV for X coordinate appears to be determining velocity X wise
Same goes for Y coordinate.
Position of both self and target cannot be same otherwise game will divide by 0
Gonna think about this later since there are too many fireworks and screaming car alarms outside.