How to rotate your angle to someones position (In lua)?
문제
Let's say that we have function setAngle(x,y,z) which works perfectly. Now we also have position of ourself and a chicken. How can we use setAngle() to aim the chicken? This would be done in an fps game? I have no idea on how to convert the positions to the angle... >.<
해결책
There is math? Let be yourself at point
A(x, y, z)
and the chicken at
B(x, y, z)
A
is part of plane E
; its points satisfying the equation
a * x + b * y + c * z = d
Considering your game, E
is possibly parallel to the XY
-plane, so we have
E : c * z = d
Then, the angle enclosed by vector AB
and the XY
-plane is the arcsin of
c * ( B[z] - A[z] ) / ( mag(n) * mag(AB) )
where mag(n)
is the magnitude of the surface normal of E
resp. of the vector AB
.
Considering your function, this might proof unnecessary, for it seems to me like adjusting things for you already.
다른 팁
It is the aTan of the slope of the line between you and the chicken. Use aTan2 though, it will work better regarding vertical directions (Thanks lhf)