Adjust animation speed depending on hunger
parent
261793c4d7
commit
91f233bbe1
|
@ -2,6 +2,8 @@
|
|||
-- Hunger
|
||||
--
|
||||
|
||||
food = {}
|
||||
food.speed = {} -- save the speed for the models mod
|
||||
local hunger = {}
|
||||
local timer = 0
|
||||
|
||||
|
@ -29,11 +31,13 @@ local function update_player_hunger(player, hunger, force)
|
|||
local hunger = math.min(hunger, 21)
|
||||
if force and hunger <= 10 then
|
||||
player:set_physics_override(1, nil, nil)
|
||||
food.speed[player:get_player_name()] = 1
|
||||
end
|
||||
if hunger > 10 and (force or hunger < 21) then
|
||||
local tmp = math.abs(hunger-20) / 20 + 0.5
|
||||
minetest.log("action", player:get_player_name() .. " is hungry and gets slower ("..(tmp*100).."% of speed)")
|
||||
player:set_physics_override(tmp, nil, nil)
|
||||
food.speed[player:get_player_name()] = tmp
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
food
|
|
@ -48,6 +48,7 @@ minetest.register_globalstep(function(dtime)
|
|||
local pitch = player:get_look_pitch()*180/math.pi
|
||||
if pitch > 50 then pitch = 50 end
|
||||
if pitch < -70 then pitch = -70 end
|
||||
local player_speed = food.speed[name] or 1
|
||||
|
||||
if walk then
|
||||
if players[name].ArmLeft.dir == 0 then
|
||||
|
@ -68,14 +69,14 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
|
||||
if sneak then
|
||||
players[name].ArmLeft.speed = 20*2
|
||||
players[name].ArmLeft.speed = 20*2 * player_speed
|
||||
players[name].ArmLeft.lim = {20, -20}
|
||||
players[name].LegLeft.speed = 30*2
|
||||
players[name].LegLeft.speed = 30*2 * player_speed
|
||||
players[name].LegLeft.lim = {30, -30}
|
||||
else
|
||||
players[name].ArmLeft.speed = 30*5
|
||||
players[name].ArmLeft.speed = 30*5 * player_speed
|
||||
players[name].ArmLeft.lim = {30, -30}
|
||||
players[name].LegLeft.speed = 40*5
|
||||
players[name].LegLeft.speed = 40*5 * player_speed
|
||||
players[name].LegLeft.lim = {40, -40}
|
||||
end
|
||||
|
||||
|
@ -95,10 +96,10 @@ minetest.register_globalstep(function(dtime)
|
|||
players[name].ArmRight.speed = 30*10
|
||||
players[name].ArmRight.lim = {-players[name].ArmLeft.rot.x+1, -players[name].ArmLeft.rot.x-1}
|
||||
elseif sneak then
|
||||
players[name].ArmRight.speed = 20*2
|
||||
players[name].ArmRight.speed = 20*2 * player_speed
|
||||
players[name].ArmRight.lim = {20, -20}
|
||||
else
|
||||
players[name].ArmRight.speed = 30*5
|
||||
players[name].ArmRight.speed = 30*5 * player_speed
|
||||
players[name].ArmRight.lim = {30, -30}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue