function rotateObjectToPoint(obj, turnSpeed, x, y, z) //store old rotate oldXa as float oldYa as float oldZa as float diff as float oldXa = wrapvalue(object angle x(obj)) oldYa = wrapvalue(object angle y(obj)) oldZa = wrapvalue(object angle z(obj)) //point to destination point object obj, x, y, z diff=wrapvalue((object angle x(obj) - oldXa) + 180) if diff-turnSpeed > 180 oldXa = oldXa + turnSpeed else if diff+turnSpeed < 180 oldXa = oldXa - turnSpeed else oldXa = object angle x(obj) endif endif diff=wrapvalue((object angle y(obj) - oldYa) + 180) if diff-turnSpeed > 180 oldYa = oldYa + turnSpeed else if diff+turnSpeed < 180 oldYa = oldYa - turnSpeed else oldYa = object angle y(obj) endif endif diff=wrapvalue((object angle z(obj) - oldZa) + 180) if diff-turnSpeed > 180 oldZa = oldZa + turnSpeed else if diff+turnSpeed < 180 oldZa = oldZa - turnSpeed else oldZa = object angle z(obj) endif endif rotate object obj, oldXa, oldYa, oldZa endfunction