1
0
Fork 0

Add smooth FOV transition when sprinting

This commit is contained in:
Brandon 2020-06-23 18:17:30 -04:00
parent b75075a135
commit d632cf289c
1 changed files with 11 additions and 6 deletions

View File

@ -33,6 +33,7 @@ minetest.register_on_joinplayer(function(player)
shouldSprint = false,
lastPos = player:get_pos(),
sprintDistance = 0,
fov = 1.0
}
end)
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 player = minetest.get_player_by_name(playerName)
if players[playerName] then
players[playerName]["sprinting"] = sprinting
players[playerName].sprinting = sprinting
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)
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")
end
return true