I would like to rotate(aim) one object at another. I don't want to use pointentity because its instant and I want it to be more gradual. Can anyone point me in the right direction? any help would be much appreciated
hot to slowly rotate one object towards another
Blitz3D Forums/Blitz3D Programming/hot to slowly rotate one object towards another Function FaceEntity(Source,Target,Rotation_smoothnes#=10)
If rotdone=False
entang#=DeltaYaw#(Source,Target)
If Abs(entang#)>Rotation_smoothnes
TurnEntity Source,0,Rotation_smoothnes*Sgn(entang#),0
Else
xdiff# = EntityX(Source)-EntityX(Target)
ydiff# = EntityY(Source)-EntityY(Target)
zdiff# = EntityZ(Source)-EntityZ(Target)
dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#))
pitch# = ATan2(ydiff#,dist#)
yaw# = ATan2(xdiff#,-zdiff#)
RotateEntity Source,0,yaw#,0
rotdone=True
EndIf
End If
End Function
This will rotate your entity only around Y axis, but for X axis just use pitch# if you need it..
If rotdone=False
entang#=DeltaYaw#(Source,Target)
If Abs(entang#)>Rotation_smoothnes
TurnEntity Source,0,Rotation_smoothnes*Sgn(entang#),0
Else
xdiff# = EntityX(Source)-EntityX(Target)
ydiff# = EntityY(Source)-EntityY(Target)
zdiff# = EntityZ(Source)-EntityZ(Target)
dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#))
pitch# = ATan2(ydiff#,dist#)
yaw# = ATan2(xdiff#,-zdiff#)
RotateEntity Source,0,yaw#,0
rotdone=True
EndIf
End If
End Function
This will rotate your entity only around Y axis, but for X axis just use pitch# if you need it..
Thanks guys!