From 34c4140cd4aec636e194a79d0394ea3378fdc307 Mon Sep 17 00:00:00 2001 From: epCode Date: Sun, 21 Feb 2021 02:45:10 +0000 Subject: [PATCH] Add swimming pitch --- mods/PLAYER/mcl_playerplus/init.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 3395a4db3..6bc9b86fb 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -11,6 +11,12 @@ local function degrees(rad) return rad * 180.0 / math.pi 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 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)) 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 - 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 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 -- controls head pitch when not sneaking -- sets eye height, and nametag color accordingly