Limit range of head rotation, ensure we cache each player separately

master^2
Jeremy 2022-03-17 18:08:27 -07:00
parent fec13ce4e7
commit c04f19c8d8
1 changed files with 13 additions and 4 deletions

View File

@ -104,18 +104,27 @@ local function yaw_to_degrees(yaw)
return(yaw * 180.0 / math.pi)
end
local last_look_at_dir
local last_look = {}
local function move_head(player, on_water)
local pname = player:get_player_name()
local look_at_dir = player:get_look_dir()
local lastlook = last_look[pname]
local anim = player_anim[pname] or ""
local anim_base = string.sub(anim, 1, 4)
--apply change only if the pitch changed
if last_look_at_dir and look_at_dir.y == last_look_at_dir.y then
if lastlook and look_at_dir.y == lastlook.dir.y and
anim_base == lastlook.anim then
return
else
last_look_at_dir = look_at_dir
last_look[pname] = {}
last_look[pname].dir = look_at_dir
last_look[pname].anim = anim_base
end
local pitch = yaw_to_degrees(math.asin(look_at_dir.y))
if on_water then
if pitch > 70 then pitch = 70 end
if pitch < -50 then pitch = -50 end
if anim_base == "swin" or on_water then
pitch = pitch + 70
end
local head_rotation = {x= pitch, y= 0, z= 0} --the head movement {pitch, yaw, roll}