yeah that would be right, soulds like what we did in another game, hmm can't remember which though. I'll see if I have the code still then I won't need to work out all that radian stuff again, might have even been GW2.
Yeah GW2 had this, which is similar in the way it uses 2 Pi for a full circle, I think lol
Code: Select all
-- self.Angle: 0 (2*Pi) = West, 1,57 (Pi/2) = South, 3,14(Pi) = East, 4,71 (Pi+Pi/2) = North
function Player:facedirection(x, z, _angle, dist)
self.curtime = getTime()
coordsupdate()
x = x or 0;
z = z or 0;
_angle = _angle or 0.1
-- Check our angle to the waypoint.
local angle = math.atan2(z - self.Z, x - self.X) + math.pi;
local angleDif = angleDifference(angle, self.Angle);
if( angleDif > _angle ) then
-- Attempt to face it
if angleDif > angleDifference(angle, self.Angle+ 0.01) then
-- Rotate left
logger:log('debug-moving','at Player:facedirection: move left angleDif: %.2f > _angle: %.2f', angleDif, _angle);
self:move("left", dist)
else
-- Rotate right
logger:log('debug-moving','at Player:facedirection: move right angleDif %.2f > _angle: %.2f', angleDif, _angle);
self:move("right",dist)
end
else
logger:log('debug-moving','at Player:facedirection: facing ok, angleDif: %.2f < _angle: %.2f', angleDif, _angle);
self:stopTurning() -- no turning after looking in right direction
return true
end
end