1
0
mirror of https://github.com/LoneWolfHT/headanim.git synced 2024-11-14 06:20:38 +01:00

Improve performance

This commit is contained in:
LoneWolfHT 2021-08-12 07:58:04 -07:00
parent daac6ff677
commit 0e79459f96

View File

@ -1,5 +1,21 @@
local get_connected_players = minetest.get_connected_players
local abs = math.abs
local deg = math.deg
local basepos = vector.new(0, 6.35, 0)
local lastdir = {}
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
player:set_bone_position("Head", vector.new(0, 6.35, 0), vector.new(-math.deg(player:get_look_vertical()), 0, 0))
for _, player in pairs(get_connected_players()) do
local pname = player:get_player_name()
local ldeg = -deg(player:get_look_vertical())
if abs((lastdir[pname] or 0) - ldeg) > 4 then
lastdir[pname] = ldeg
player:set_bone_position("Head", basepos, {x = ldeg, y = 0, z = 0})
end
end
end)
minetest.register_on_leaveplayer(function(player)
lastdir[player:get_player_name()] = nil
end)