do what ShadowNinja suggested

This commit is contained in:
HybridDog 2014-10-02 21:40:10 +02:00
parent 1c060ff5ad
commit 18c1930e5b

View file

@ -161,7 +161,9 @@ minetest.register_on_leaveplayer(function(player)
end) end)
if not minetest.is_singleplayer() then if minetest.is_singleplayer() then
return
end
-- Localize for better performance. -- Localize for better performance.
local player_set_animation = default.player_set_animation local player_set_animation = default.player_set_animation
@ -179,11 +181,11 @@ minetest.register_globalstep(function(dtime)
local pos = player:getpos() local pos = player:getpos()
pos.y = nil pos.y = nil
local lastpos = ps[name] or {x=0, z=0} local lastpos = ps[name] or {x=0, z=0}
local v local animation_speed
if not (lastpos.x == pos.x if not (lastpos.x == pos.x
and lastpos.z == pos.z) then and lastpos.z == pos.z) then
ps[name] = pos ps[name] = pos
v = 6*math.hypot(lastpos.x-pos.x, lastpos.z-pos.z)/dtime animation_speed = 6*math.hypot(lastpos.x-pos.x, lastpos.z-pos.z)/dtime
end end
local controls = player:get_player_control() local controls = player:get_player_control()
@ -191,15 +193,15 @@ minetest.register_globalstep(function(dtime)
-- Apply animations based on what the player is doing -- Apply animations based on what the player is doing
if player:get_hp() == 0 then if player:get_hp() == 0 then
player_set_animation(player, "lay") player_set_animation(player, "lay")
elseif v then elseif animation_speed then
if player_sneak[name] ~= controls.sneak then if player_sneak[name] ~= controls.sneak then
player_anim[name] = nil player_anim[name] = nil
player_sneak[name] = controls.sneak player_sneak[name] = controls.sneak
end end
if controls.LMB then if controls.LMB then
player_set_animation(player, "walk_mine", v) player_set_animation(player, "walk_mine", animation_speed)
else else
player_set_animation(player, "walk", v) player_set_animation(player, "walk", animation_speed)
end end
elseif controls.LMB then elseif controls.LMB then
player_set_animation(player, "mine") player_set_animation(player, "mine")
@ -209,5 +211,3 @@ minetest.register_globalstep(function(dtime)
end end
end end
end) end)
end