Here's a note I made to myself long ago.
; What is DeltaYaw?
; There are two entities, a source and a destination ( target ).
; Imagine the center ( origin ) of the target projected onto the X-Z plane.
; i.e. ignore the y-coordinate. Do the same with the Z+ axis of the source.
; Think of this projected axis as a vector ( arrow ) in the X-Z plane.
; How much must it be turned to point at the target? The answer is DeltaYaw( source, target )
; This should always give the angle through which source must be turned about
; the vertical ( global Y ) axis.
Function Delta_Yaw#( src, dest ) ; Simulate DeltaYaw
dx# = EntityX(dest,True) - EntityX(src,True)
dz# = EntityZ(dest,True) - EntityZ(src,True)
angle# = ATan2( -dx, dz ) - EntityYaw(src,True)
If angle <= -180 Then angle = angle + 360
If angle > +180 Then angle = angle - 360
Return angle
End Function
|