Code archives/Miscellaneous/Curve Angle

This code has not been declared by its author to be Public Domain code, and therefore should not be assumed to be so.

Download source code

Curve Angle by Ice9
(Posted 25 years ago)
Returns a value between the current angle and the desired angle based on the curve value.

Use full for adding smooth movements rather than a sudden jerk or turn
Function curveangle#( currentangle#,desiredangle#,curve# )
	

	Adist#=	Sqr((DesiredAngle#-CurrentAngle#)*(DesiredAngle#-CurrentAngle#))
    If DesiredAngle>CurrentAngle 
		If Adist#>180 
			CurrentAngle=CurrentAngle-(Adist#/curve)
			If CurrentAngle<-180 Then CurrentAngle=CurrentAngle+360
		Else
			Adist#=360-Adist#
			CurrentAngle=CurrentAngle+(Adist#/curve)
			If CurrentAngle>180 Then CurrentAngle=CurrentAngle-360
		EndIf
		
    Else
		If ADist#>180 
			CurrentAngle=CurrentAngle+(Adist#/curve)
			If CurrentAngle>180 Then CurrentAngle=CurrentAngle-360
		Else
			Adist#=360-Adist#
			CurrentAngle=CurrentAngle-(Adist#/curve)
			If CurrentAngle<-180 Then CurrentAngle=CurrentAngle+360
		EndIf
    EndIf
			
	Return CurrentAngle
	
End Function