Add swimming pitch

This commit is contained in:
epCode 2021-02-21 02:45:10 +00:00
parent 017f14c563
commit 34c4140cd4
1 changed files with 8 additions and 2 deletions

View File

@ -11,6 +11,12 @@ local function degrees(rad)
return rad * 180.0 / math.pi return rad * 180.0 / math.pi
end end
local dir_to_pitch = function(dir)
local dir2 = vector.normalize(dir)
local xz = math.abs(dir.x) + math.abs(dir.z)
return -math.atan2(-dir.y, xz)
end
local pitch, name, node_stand, node_stand_below, node_head, node_feet, pos local pitch, name, node_stand, node_stand_below, node_head, node_feet, pos
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
@ -69,11 +75,11 @@ minetest.register_globalstep(function(dtime)
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0)) player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0))
elseif minetest.get_item_group(mcl_playerinfo[name].node_feet, "water") ~= 0 and player:get_attach() == nil and mcl_sprint.is_sprinting(name) == true then elseif minetest.get_item_group(mcl_playerinfo[name].node_feet, "water") ~= 0 and player:get_attach() == nil and mcl_sprint.is_sprinting(name) == true then
-- controls head pitch when swiming -- controls head pitch when swiming
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,yaw - player_vel_yaw * -1,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90-degrees(dir_to_pitch(player_velocity)),yaw - player_vel_yaw * -1,0))
-- sets eye height, and nametag color accordingly -- sets eye height, and nametag color accordingly
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(-90,player_vel_yaw * -1 - yaw + 180,0)) player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,player_vel_yaw * -1 - yaw + 180,0))
else else
-- controls head pitch when not sneaking -- controls head pitch when not sneaking
-- sets eye height, and nametag color accordingly -- sets eye height, and nametag color accordingly