Function TurnToward(angle,goalangle,turnspeed)
difference=wrapvalue(angle-goalangle)
if difference>=180
angle=wrapvalue(angle+speed)
endif
if difference<180
angle=wrapvalue(angle-speed)
endif
endfunction angle
Here's an alternate one based on Andy Igoe's code I haven't tried this one, but it looks like it works:
function Turntoward(Angle#,Goalangle#, Turnspeed#)
turn#=180-wrapvalue((Angle#-Goalangle#)-180)
turn#= (turn#/abs(turn#))*turnspeed#
endfunction turn#
Actually I just condensed my code using boolean math...
Function Turntoward(angle#,goalangle#,speed#)
angle# = wrapvalue(angle#+(speed#*(wrapvalue(angle#-goalangle)>180)-speed#*(wrapvalue(angle#-goalangle)<=180))
endfunction angle#