forked from MineClone5/MineClone5
Add smooth FOV transition when sprinting
This commit is contained in:
parent
b75075a135
commit
d632cf289c
|
@ -2,9 +2,9 @@
|
||||||
Sprint mod for Minetest by GunshipPenguin
|
Sprint mod for Minetest by GunshipPenguin
|
||||||
|
|
||||||
To the extent possible under law, the author(s)
|
To the extent possible under law, the author(s)
|
||||||
have dedicated all copyright and related and neighboring rights
|
have dedicated all copyright and related and neighboring rights
|
||||||
to this software to the public domain worldwide. This software is
|
to this software to the public domain worldwide. This software is
|
||||||
distributed without any warranty.
|
distributed without any warranty.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
--Configuration variables, these are all explained in README.md
|
--Configuration variables, these are all explained in README.md
|
||||||
|
@ -29,10 +29,11 @@ minetest.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
players[playerName] = {
|
players[playerName] = {
|
||||||
sprinting = false,
|
sprinting = false,
|
||||||
timeOut = 0,
|
timeOut = 0,
|
||||||
shouldSprint = false,
|
shouldSprint = false,
|
||||||
lastPos = player:get_pos(),
|
lastPos = player:get_pos(),
|
||||||
sprintDistance = 0,
|
sprintDistance = 0,
|
||||||
|
fov = 1.0
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
@ -43,10 +44,14 @@ end)
|
||||||
local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)
|
local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting)
|
||||||
local player = minetest.get_player_by_name(playerName)
|
local player = minetest.get_player_by_name(playerName)
|
||||||
if players[playerName] then
|
if players[playerName] then
|
||||||
players[playerName]["sprinting"] = sprinting
|
players[playerName].sprinting = sprinting
|
||||||
if sprinting == true then
|
if sprinting == true then
|
||||||
|
players[playerName].fov = math.min(players[playerName].fov + 0.02, 1.2)
|
||||||
|
player:set_fov(players[playerName].fov, true, 0.15)
|
||||||
playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
|
playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
|
||||||
elseif sprinting == false then
|
elseif sprinting == false then
|
||||||
|
players[playerName].fov = math.max(players[playerName].fov - 0.02, 1.0)
|
||||||
|
player:set_fov(players[playerName].fov, true, 0.15)
|
||||||
playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
|
playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
@ -68,7 +73,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
else
|
else
|
||||||
players[playerName]["shouldSprint"] = false
|
players[playerName]["shouldSprint"] = false
|
||||||
end
|
end
|
||||||
|
|
||||||
local playerPos = player:get_pos()
|
local playerPos = player:get_pos()
|
||||||
--If the player is sprinting, create particles behind and cause exhaustion
|
--If the player is sprinting, create particles behind and cause exhaustion
|
||||||
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
if playerInfo["sprinting"] == true and gameTime % 0.1 == 0 then
|
||||||
|
@ -117,7 +122,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
elseif players[playerName]["shouldSprint"] == false then
|
elseif players[playerName]["shouldSprint"] == false then
|
||||||
setSprinting(playerName, false)
|
setSprinting(playerName, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue