From 8f4388c4c827cce1d20930ceab05bd1a0b419273 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 17:42:43 +1000 Subject: [PATCH 01/36] elytra less sensitive to landing, allows entering flight without as much downward velocity --- mods/PLAYER/mcl_playerplus/init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index c3876269c..2c44a88d5 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -259,12 +259,17 @@ minetest.register_globalstep(function(dtime) player_vel_yaws[name] = player_vel_yaw local fly_pos = player:get_pos() - local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.5, z = fly_pos.z}).name + local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.05, z = fly_pos.z}).name local elytra = mcl_playerplus.elytra[player] + local function get_overall_velocity(vector) + local v = sqrt(vector.x^2 + vector.y^2 + vector.z^2) + return 0 + end + elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and not player:get_attach() - and (elytra.active or control.jump and player_velocity.y < -6) + and (elytra.active or (control.jump and player_velocity.y < -1)) and (fly_node == "air" or fly_node == "ignore") if elytra.active then @@ -629,7 +634,7 @@ minetest.register_on_joinplayer(function(player) swimDistance = 0, jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly } - mcl_playerplus.elytra[player] = {active = false, rocketing = 0} + mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0} end) -- clear when player leaves From 696cc150b4b8dca04ef10d055ddc005ac12ce50e Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 20:12:53 +1000 Subject: [PATCH 02/36] broke elytra --- mods/PLAYER/mcl_playerplus/init.lua | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 2c44a88d5..902eb12cc 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -263,8 +263,16 @@ minetest.register_globalstep(function(dtime) local elytra = mcl_playerplus.elytra[player] local function get_overall_velocity(vector) - local v = sqrt(vector.x^2 + vector.y^2 + vector.z^2) - return 0 + local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2) + return v + end + + local function clamp(num, min, max) + return math.min(max, math.max(num, min)) + end + + if not elytra.active then + elytra.speed = 10 end elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" @@ -274,18 +282,18 @@ minetest.register_globalstep(function(dtime) if elytra.active then mcl_player.player_set_animation(player, "fly") - if player_velocity.y < -1.5 then - player:add_velocity({x=0, y=0.17, z=0}) - end - if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - if degrees(player:get_look_vertical()) * -.01 < .1 then - look_pitch = degrees(player:get_look_vertical()) * -.01 - else - look_pitch = .1 - end - player:add_velocity({x=dir.x, y=look_pitch, z=dir.z}) - end + local max_speed = 10000 + local direction = player:get_look_dir() + -- local vel = player:get_velocity() + local speed_mult = clamp(elytra.speed - direction.y * dtime, -max_speed, max_speed) + elytra.speed = speed_mult + vel = direction + vel = vector.multiply(vel, speed_mult*100) + vel = { + x = clamp(vel.x, -max_speed, max_speed), + y = clamp(vel.y, -max_speed, max_speed), + z = clamp(vel.z, -max_speed, max_speed)} + player:set_velocity(vel) playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) if elytra.rocketing > 0 then From 177cf231b6b9a9b042a0d8b0c73f5d10b0ee1462 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 20:34:56 +1000 Subject: [PATCH 03/36] make elytra better again --- mods/PLAYER/mcl_playerplus/init.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 902eb12cc..8a9771e46 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -282,18 +282,27 @@ minetest.register_globalstep(function(dtime) if elytra.active then mcl_player.player_set_animation(player, "fly") - local max_speed = 10000 + local slowdown_mult = 0.7 -- amount of vel to take + local max_speed = 1000 local direction = player:get_look_dir() - -- local vel = player:get_velocity() - local speed_mult = clamp(elytra.speed - direction.y * dtime, -max_speed, max_speed) + local v = player:get_velocity() + local speed_mult = clamp(elytra.speed - direction.y * 30 * dtime, -max_speed, max_speed) + speed_mult = speed_mult - slowdown_mult * speed_mult * dtime -- slow down + speed_mult = math.max(speed_mult, -1) elytra.speed = speed_mult vel = direction - vel = vector.multiply(vel, speed_mult*100) - vel = { - x = clamp(vel.x, -max_speed, max_speed), - y = clamp(vel.y, -max_speed, max_speed), - z = clamp(vel.z, -max_speed, max_speed)} - player:set_velocity(vel) + vel = vector.multiply(vel, speed_mult) + -- vel = { + -- x = clamp(vel.x, -max_speed, max_speed), + -- y = clamp(vel.y, -max_speed, max_speed), + -- z = clamp(vel.z, -max_speed, max_speed)} + + -- slow the player down so less spongy movement by applying half the inverse vel + -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken + v = vector.multiply(v, -0.3) + player:add_velocity(v) + vel.y = vel.y - (100 / math.max(speed_mult, 1)) * dtime + player:add_velocity(vel) playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) if elytra.rocketing > 0 then From 832b0afdd63ffc090ada94dcba67a8c4e41647eb Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 20:51:08 +1000 Subject: [PATCH 04/36] more reasonable values --- mods/PLAYER/mcl_playerplus/init.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 8a9771e46..f786d696d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -282,26 +282,29 @@ minetest.register_globalstep(function(dtime) if elytra.active then mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 0.7 -- amount of vel to take - local max_speed = 1000 + local slowdown_mult = 0.2 -- amount of vel to take + local speedup_mult = 10 -- amount of speed to add based on look dir + local max_speed = 60 local direction = player:get_look_dir() local v = player:get_velocity() - local speed_mult = clamp(elytra.speed - direction.y * 30 * dtime, -max_speed, max_speed) + local direction_mult = clamp(direction.y*2, -0.5, 0.5) + local speed_mult = clamp(elytra.speed - direction_mult * speedup_mult * dtime, -max_speed, max_speed) speed_mult = speed_mult - slowdown_mult * speed_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) + speed_mult = math.min(speed_mult, max_speed) elytra.speed = speed_mult vel = direction vel = vector.multiply(vel, speed_mult) - -- vel = { - -- x = clamp(vel.x, -max_speed, max_speed), - -- y = clamp(vel.y, -max_speed, max_speed), - -- z = clamp(vel.z, -max_speed, max_speed)} + vel = { + x = clamp(vel.x, -max_speed, max_speed), + y = clamp(vel.y, -max_speed, max_speed), + z = clamp(vel.z, -max_speed, max_speed)} -- slow the player down so less spongy movement by applying half the inverse vel -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken v = vector.multiply(v, -0.3) player:add_velocity(v) - vel.y = vel.y - (100 / math.max(speed_mult, 1)) * dtime + vel.y = vel.y - (100 / math.max(speed_mult, 2)) * dtime player:add_velocity(vel) playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) From 20b229a9b9a5daf6e12ce441d83a409a2d82dc55 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 20:53:35 +1000 Subject: [PATCH 05/36] pitching up too far can make player fall fast --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index f786d696d..1b938aaa1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -304,7 +304,7 @@ minetest.register_globalstep(function(dtime) -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken v = vector.multiply(v, -0.3) player:add_velocity(v) - vel.y = vel.y - (100 / math.max(speed_mult, 2)) * dtime + vel.y = vel.y - (300 / math.max(speed_mult, 1)) * dtime player:add_velocity(vel) playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) From 9e1b0184c57d251c17b1863584f3808a01d93a2c Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 22:15:36 +1000 Subject: [PATCH 06/36] fireworks function, slight balancing, removed debug starting speed --- mods/PLAYER/mcl_playerplus/init.lua | 49 ++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 1b938aaa1..bf5143271 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -266,13 +266,17 @@ minetest.register_globalstep(function(dtime) local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2) return v end + local function anglediff(a1, a2) + local a = a1 - a2 + return math.abs((a + math.pi) % (math.pi*2) - math.pi) + end local function clamp(num, min, max) return math.min(max, math.max(num, min)) end if not elytra.active then - elytra.speed = 10 + elytra.speed = 2 end elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" @@ -282,36 +286,26 @@ minetest.register_globalstep(function(dtime) if elytra.active then mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 0.2 -- amount of vel to take + local slowdown_mult = 0.2 -- amount of vel to take per sec local speedup_mult = 10 -- amount of speed to add based on look dir - local max_speed = 60 + local max_speed = 120 local direction = player:get_look_dir() local v = player:get_velocity() - local direction_mult = clamp(direction.y*2, -0.5, 0.5) - local speed_mult = clamp(elytra.speed - direction_mult * speedup_mult * dtime, -max_speed, max_speed) + local direction_mult = clamp(-direction.y*2, -0.5, 0.5) + local speed_mult = clamp(elytra.speed + direction_mult * speedup_mult * dtime, -max_speed, max_speed) speed_mult = speed_mult - slowdown_mult * speed_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) elytra.speed = speed_mult vel = direction - vel = vector.multiply(vel, speed_mult) - vel = { - x = clamp(vel.x, -max_speed, max_speed), - y = clamp(vel.y, -max_speed, max_speed), - z = clamp(vel.z, -max_speed, max_speed)} - -- slow the player down so less spongy movement by applying half the inverse vel - -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken - v = vector.multiply(v, -0.3) - player:add_velocity(v) - vel.y = vel.y - (300 / math.max(speed_mult, 1)) * dtime - player:add_velocity(vel) playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) - if elytra.rocketing > 0 then elytra.rocketing = elytra.rocketing - dtime if vector.length(player_velocity) < 40 then - player:add_velocity(vector.multiply(player:get_look_dir(), 4)) + -- player:add_velocity(vector.multiply(player:get_look_dir(), 4)) + speed_mult = 30 + elytra.speed = speed_mult add_particle({ pos = fly_pos, velocity = {x = 0, y = 0, z = 0}, @@ -324,10 +318,23 @@ minetest.register_globalstep(function(dtime) glow = 5, }) end + else + elytra.rocketing = 0 + playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end - else - elytra.rocketing = 0 - playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") + + vel = vector.multiply(vel, speed_mult) + vel = { + x = clamp(vel.x, -max_speed, max_speed), + y = clamp(vel.y, -max_speed, max_speed), + z = clamp(vel.z, -max_speed, max_speed)} + + -- slow the player down so less spongy movement by applying half the inverse vel + -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken + v = vector.multiply(v, -0.4) + player:add_velocity(v) + vel.y = vel.y - (200 / math.max(speed_mult+1, 1)) * dtime + player:add_velocity(vel) end if wielded_def and wielded_def._mcl_toollike_wield then From cd622783368ad4a9c803a221301a0a03d0ce20b1 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 23:01:27 +1000 Subject: [PATCH 07/36] improved code quality --- mods/PLAYER/mcl_playerplus/init.lua | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index bf5143271..c6c83dd9a 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -3,6 +3,7 @@ mcl_playerplus = { } local player_velocity_old = {x=0, y=0, z=0} +local player_position_old = {x=0, y=0, z=0} local get_connected_players = minetest.get_connected_players local dir_to_yaw = minetest.dir_to_yaw local get_item_group = minetest.get_item_group @@ -286,18 +287,20 @@ minetest.register_globalstep(function(dtime) if elytra.active then mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 0.2 -- amount of vel to take per sec - local speedup_mult = 10 -- amount of speed to add based on look dir + local slowdown_mult = 1 -- amount of vel to take per sec + local fall_speed = 40 -- amount to fall down per sec in nodes + local speedup_mult = 15 -- amount of speed to add based on look dir local max_speed = 120 local direction = player:get_look_dir() - local v = player:get_velocity() + local player_vel = player:get_velocity() local direction_mult = clamp(-direction.y*2, -0.5, 0.5) - local speed_mult = clamp(elytra.speed + direction_mult * speedup_mult * dtime, -max_speed, max_speed) - speed_mult = speed_mult - slowdown_mult * speed_mult * dtime -- slow down + + local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime + speed_mult = speed_mult - slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) - elytra.speed = speed_mult - vel = direction + elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it + new_vel = direction -- use the facing direction as a base playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) if elytra.rocketing > 0 then @@ -323,18 +326,20 @@ minetest.register_globalstep(function(dtime) playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end - vel = vector.multiply(vel, speed_mult) - vel = { - x = clamp(vel.x, -max_speed, max_speed), - y = clamp(vel.y, -max_speed, max_speed), - z = clamp(vel.z, -max_speed, max_speed)} + new_vel = vector.multiply(new_vel, speed_mult) + new_vel = { + x = clamp(new_vel.x, -max_speed, max_speed), + y = clamp(new_vel.y, -max_speed, max_speed), + z = clamp(new_vel.z, -max_speed, max_speed)} -- slow the player down so less spongy movement by applying half the inverse vel -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken - v = vector.multiply(v, -0.4) - player:add_velocity(v) - vel.y = vel.y - (200 / math.max(speed_mult+1, 1)) * dtime - player:add_velocity(vel) + -- this is far from ideal, but there's no good way to set_velocity on the player + player_vel = vector.multiply(player_vel, -0.4) + player:add_velocity(player_vel) + new_vel.y = new_vel.y - (400 / math.max(speed_mult, 2)) * dtime + new_vel.y = new_vel.y - fall_speed * dtime + player:add_velocity(new_vel) end if wielded_def and wielded_def._mcl_toollike_wield then @@ -350,6 +355,7 @@ minetest.register_globalstep(function(dtime) end player_velocity_old = player:get_velocity() or player:get_player_velocity() + player_position_old = player:get_pos() -- controls right and left arms pitch when shooting a bow or blocking From 368ffda75be1a66b8259d3db38e83d5a3066b1b6 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 1 Aug 2022 23:45:41 +1000 Subject: [PATCH 08/36] can only fly when pressed jump and cannot hold jump to enter fly mode, set speed to player velocity when entered fly mode --- mods/PLAYER/mcl_playerplus/init.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index c6c83dd9a..94ebef52d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -4,6 +4,7 @@ mcl_playerplus = { local player_velocity_old = {x=0, y=0, z=0} local player_position_old = {x=0, y=0, z=0} +local is_pressing_jump = false local get_connected_players = minetest.get_connected_players local dir_to_yaw = minetest.dir_to_yaw local get_item_group = minetest.get_item_group @@ -280,15 +281,21 @@ minetest.register_globalstep(function(dtime) elytra.speed = 2 end + local is_just_jumped = control.jump and not is_pressing_jump + is_pressing_jump = control.jump + if is_just_jumped and not elytra.active then + elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 20) + end + elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and not player:get_attach() - and (elytra.active or (control.jump and player_velocity.y < -1)) + and (elytra.active or (is_just_jumped and player_velocity.y < -0)) and (fly_node == "air" or fly_node == "ignore") if elytra.active then mcl_player.player_set_animation(player, "fly") local slowdown_mult = 1 -- amount of vel to take per sec - local fall_speed = 40 -- amount to fall down per sec in nodes + local fall_speed = 10 -- amount to fall down per sec in nodes local speedup_mult = 15 -- amount of speed to add based on look dir local max_speed = 120 local direction = player:get_look_dir() @@ -299,6 +306,7 @@ minetest.register_globalstep(function(dtime) speed_mult = speed_mult - slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) + elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it new_vel = direction -- use the facing direction as a base @@ -337,7 +345,7 @@ minetest.register_globalstep(function(dtime) -- this is far from ideal, but there's no good way to set_velocity on the player player_vel = vector.multiply(player_vel, -0.4) player:add_velocity(player_vel) - new_vel.y = new_vel.y - (400 / math.max(speed_mult, 2)) * dtime + new_vel.y = new_vel.y - (200 / math.max(speed_mult, 2)) * dtime new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) end From 2b5e3b5123505b943395ddf7cd2f6d2ca8a7f73a Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 00:14:24 +1000 Subject: [PATCH 09/36] code quality: combine add_velocity calls into one --- mods/PLAYER/mcl_playerplus/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 94ebef52d..726d05151 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -344,7 +344,8 @@ minetest.register_globalstep(function(dtime) -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player player_vel = vector.multiply(player_vel, -0.4) - player:add_velocity(player_vel) + new_vel = vector.add(new_vel, player_vel) + new_vel.y = new_vel.y - (200 / math.max(speed_mult, 2)) * dtime new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) From 8378ca92e22ba92a562bf2fc8286141b8c7dd636 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 08:20:08 +1000 Subject: [PATCH 10/36] turning slows the player down in fly mode --- mods/PLAYER/mcl_playerplus/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 726d05151..b950aba91 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -300,12 +300,14 @@ minetest.register_globalstep(function(dtime) local max_speed = 120 local direction = player:get_look_dir() local player_vel = player:get_velocity() + local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) local direction_mult = clamp(-direction.y*2, -0.5, 0.5) local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) + speed_mult = speed_mult - (speed_mult * turn_amount / (math.pi*3)) elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it new_vel = direction -- use the facing direction as a base From 5fd66d1850b92545ddacbf404b74211c8c03755e Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 18:12:15 +1000 Subject: [PATCH 11/36] can pitch up without losing too much speed --- mods/PLAYER/mcl_playerplus/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b950aba91..2b3e1555b 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -296,12 +296,13 @@ minetest.register_globalstep(function(dtime) mcl_player.player_set_animation(player, "fly") local slowdown_mult = 1 -- amount of vel to take per sec local fall_speed = 10 -- amount to fall down per sec in nodes - local speedup_mult = 15 -- amount of speed to add based on look dir + local speedup_mult = 10 -- amount of speed to add based on look dir local max_speed = 120 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-direction.y*2, -0.5, 0.5) + local direction_mult = clamp(-direction.y + 0, -1, 1) + if direction_mult < 0 then direction_mult = -(direction_mult^2) + direction_mult/2 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down From 1468acf6d419822dfdea51016a59374eff405c0a Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 18:26:00 +1000 Subject: [PATCH 12/36] move player up to give clearance when start flying --- mods/PLAYER/mcl_playerplus/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 2b3e1555b..3448d9fa1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -281,7 +281,7 @@ minetest.register_globalstep(function(dtime) elytra.speed = 2 end - local is_just_jumped = control.jump and not is_pressing_jump + local is_just_jumped = control.jump and not is_pressing_jump and not elytra.active is_pressing_jump = control.jump if is_just_jumped and not elytra.active then elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 20) @@ -293,6 +293,9 @@ minetest.register_globalstep(function(dtime) and (fly_node == "air" or fly_node == "ignore") if elytra.active then + if is_just_jumped then -- move the player up when they start flying to give some clearance + player:set_pos(vector.offset(player:get_pos(), 0, 0.8, 0)) + end mcl_player.player_set_animation(player, "fly") local slowdown_mult = 1 -- amount of vel to take per sec local fall_speed = 10 -- amount to fall down per sec in nodes From 0f6a51a03159a832b130ae0df82f33127fcd4ab2 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 18:39:15 +1000 Subject: [PATCH 13/36] remove unused file scope variables --- mods/PLAYER/mcl_playerplus/init.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 3448d9fa1..7257290b9 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -2,8 +2,6 @@ mcl_playerplus = { elytra = {}, } -local player_velocity_old = {x=0, y=0, z=0} -local player_position_old = {x=0, y=0, z=0} local is_pressing_jump = false local get_connected_players = minetest.get_connected_players local dir_to_yaw = minetest.dir_to_yaw @@ -369,10 +367,6 @@ minetest.register_globalstep(function(dtime) set_bone_position_conditional(player,"Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90)) end - player_velocity_old = player:get_velocity() or player:get_player_velocity() - player_position_old = player:get_pos() - - -- controls right and left arms pitch when shooting a bow or blocking if mcl_shields.is_blocking(player) == 2 then set_bone_position_conditional(player, "Arm_Right_Pitch_Control", vector.new(-3, 5.785, 0), vector.new(20, -20, 0)) From c80012a14fe4bb5bdf25def688feda3e31969ce4 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 21:23:05 +1000 Subject: [PATCH 14/36] fix gravity not being reset when died after rocketing --- mods/PLAYER/mcl_playerplus/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 7257290b9..b46414646 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -333,9 +333,6 @@ minetest.register_globalstep(function(dtime) glow = 5, }) end - else - elytra.rocketing = 0 - playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end new_vel = vector.multiply(new_vel, speed_mult) @@ -353,6 +350,9 @@ minetest.register_globalstep(function(dtime) new_vel.y = new_vel.y - (200 / math.max(speed_mult, 2)) * dtime new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) + else + elytra.rocketing = 0 + playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end if wielded_def and wielded_def._mcl_toollike_wield then From 5c085bd28f2fca9df138a73e270748f859c9d781 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 22:06:19 +1000 Subject: [PATCH 15/36] prevent player gaining infinite momentum by spamming jump while running, added dtime dependent velocity --- mods/PLAYER/mcl_playerplus/init.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b46414646..e6d000b0c 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -284,6 +284,11 @@ minetest.register_globalstep(function(dtime) if is_just_jumped and not elytra.active then elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 20) end + -- don't let player get too fast by spamming jump + local block_below = minetest.get_node(vector.offset(player:get_velocity(), 0, -0.7, 0)).name + if minetest.registered_nodes[block_below].walkable then + elytra.speed = clamp(elytra.speed, -1, 5) + end elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and not player:get_attach() @@ -298,18 +303,20 @@ minetest.register_globalstep(function(dtime) local slowdown_mult = 1 -- amount of vel to take per sec local fall_speed = 10 -- amount to fall down per sec in nodes local speedup_mult = 10 -- amount of speed to add based on look dir - local max_speed = 120 + local max_speed = 300 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) local direction_mult = clamp(-direction.y + 0, -1, 1) - if direction_mult < 0 then direction_mult = -(direction_mult^2) + direction_mult/2 end + if direction_mult < 0 then direction_mult = -(direction_mult^2) end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) - speed_mult = speed_mult - (speed_mult * turn_amount / (math.pi*3)) + if turn_amount > 0.1 then + speed_mult = speed_mult - (speed_mult * turn_amount / (math.pi*3)) + end elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it new_vel = direction -- use the facing direction as a base @@ -335,7 +342,7 @@ minetest.register_globalstep(function(dtime) end end - new_vel = vector.multiply(new_vel, speed_mult) + new_vel = vector.multiply(new_vel, speed_mult * dtime * 30) new_vel = { x = clamp(new_vel.x, -max_speed, max_speed), y = clamp(new_vel.y, -max_speed, max_speed), @@ -344,7 +351,7 @@ minetest.register_globalstep(function(dtime) -- slow the player down so less spongy movement by applying half the inverse vel -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player - player_vel = vector.multiply(player_vel, -0.4) + player_vel = vector.multiply(player_vel, -0.4 * dtime * 30) new_vel = vector.add(new_vel, player_vel) new_vel.y = new_vel.y - (200 / math.max(speed_mult, 2)) * dtime From 32a57133ac648a5266bd5659b3dbb5bab1aecfec Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 22:47:51 +1000 Subject: [PATCH 16/36] use dtime --- mods/PLAYER/mcl_playerplus/init.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index e6d000b0c..e09c463f7 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -314,8 +314,8 @@ minetest.register_globalstep(function(dtime) speed_mult = speed_mult - slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) - if turn_amount > 0.1 then - speed_mult = speed_mult - (speed_mult * turn_amount / (math.pi*3)) + if turn_amount > 0.3 then + speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*3))) end elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it @@ -342,11 +342,12 @@ minetest.register_globalstep(function(dtime) end end - new_vel = vector.multiply(new_vel, speed_mult * dtime * 30) + new_vel = vector.multiply(new_vel, speed_mult) new_vel = { x = clamp(new_vel.x, -max_speed, max_speed), y = clamp(new_vel.y, -max_speed, max_speed), z = clamp(new_vel.z, -max_speed, max_speed)} + new_vel = vector.multiply(new_vel, dtime * 30) -- slow the player down so less spongy movement by applying half the inverse vel -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken @@ -697,6 +698,9 @@ end) -- Don't change HP if the player falls in the water or through End Portal: mcl_damage.register_modifier(function(obj, damage, reason) if reason.type == "fall" then + if minetest.is_creative_enabled(obj:get_player_name()) then + return 0 + end local pos = obj:get_pos() local node = minetest.get_node(pos) local velocity = obj:get_velocity() or obj:get_player_velocity() or {x=0,y=-10,z=0} From 12af0e7de8fbba8a4174b3a32fae969cbb799099 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 23:42:04 +1000 Subject: [PATCH 17/36] semi-working on 0.3 server step --- mods/PLAYER/mcl_playerplus/init.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index e09c463f7..84a1af04f 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -300,15 +300,15 @@ minetest.register_globalstep(function(dtime) player:set_pos(vector.offset(player:get_pos(), 0, 0.8, 0)) end mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 1 -- amount of vel to take per sec - local fall_speed = 10 -- amount to fall down per sec in nodes + local slowdown_mult = 0.2 -- amount of vel to take per sec + local fall_speed = 20 -- amount to fall down per sec in nodes local speedup_mult = 10 -- amount of speed to add based on look dir - local max_speed = 300 + local max_speed = 100 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-direction.y + 0, -1, 1) - if direction_mult < 0 then direction_mult = -(direction_mult^2) end + local direction_mult = clamp(-direction.y + 0, -0.8, 1) + if direction_mult < 0 then direction_mult = -(direction_mult^2) / 2 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down @@ -326,7 +326,7 @@ minetest.register_globalstep(function(dtime) elytra.rocketing = elytra.rocketing - dtime if vector.length(player_velocity) < 40 then -- player:add_velocity(vector.multiply(player:get_look_dir(), 4)) - speed_mult = 30 + speed_mult = 10 elytra.speed = speed_mult add_particle({ pos = fly_pos, @@ -347,15 +347,15 @@ minetest.register_globalstep(function(dtime) x = clamp(new_vel.x, -max_speed, max_speed), y = clamp(new_vel.y, -max_speed, max_speed), z = clamp(new_vel.z, -max_speed, max_speed)} - new_vel = vector.multiply(new_vel, dtime * 30) + -- new_vel = vector.multiply(new_vel, dtime * 30) -- slow the player down so less spongy movement by applying half the inverse vel -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player - player_vel = vector.multiply(player_vel, -0.4 * dtime * 30) + player_vel = vector.multiply(player_vel, -0.1) new_vel = vector.add(new_vel, player_vel) - new_vel.y = new_vel.y - (200 / math.max(speed_mult, 2)) * dtime + new_vel.y = new_vel.y - (100 / math.max(speed_mult, 1)) * dtime new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) else From aa93ce4b3a2e4673484078e1b50b2a9ba5153144 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 23:45:20 +1000 Subject: [PATCH 18/36] tweaked slowdown on pitch up --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 84a1af04f..f5998760b 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -307,7 +307,7 @@ minetest.register_globalstep(function(dtime) local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-direction.y + 0, -0.8, 1) + local direction_mult = clamp(-direction.y - 0.2, -0.8, 1) if direction_mult < 0 then direction_mult = -(direction_mult^2) / 2 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime From 845e43c1439073c90e65dab8cdbc3ad475afb38e Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 2 Aug 2022 23:51:21 +1000 Subject: [PATCH 19/36] tweaked several things --- mods/PLAYER/mcl_playerplus/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index f5998760b..19b8c7839 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -302,7 +302,7 @@ minetest.register_globalstep(function(dtime) mcl_player.player_set_animation(player, "fly") local slowdown_mult = 0.2 -- amount of vel to take per sec local fall_speed = 20 -- amount to fall down per sec in nodes - local speedup_mult = 10 -- amount of speed to add based on look dir + local speedup_mult = 5 -- amount of speed to add based on look dir local max_speed = 100 local direction = player:get_look_dir() local player_vel = player:get_velocity() @@ -355,7 +355,7 @@ minetest.register_globalstep(function(dtime) player_vel = vector.multiply(player_vel, -0.1) new_vel = vector.add(new_vel, player_vel) - new_vel.y = new_vel.y - (100 / math.max(speed_mult, 1)) * dtime + new_vel.y = new_vel.y - (200 / math.max(speed_mult*10, 2)) * dtime new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) else From ece79cad8a69c49d24d9c03978241810554c35eb Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 3 Aug 2022 00:08:30 +1000 Subject: [PATCH 20/36] prevent player from getting hyperspeed while flying from ground --- mods/PLAYER/mcl_playerplus/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 19b8c7839..cf8eafc2e 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -282,7 +282,7 @@ minetest.register_globalstep(function(dtime) local is_just_jumped = control.jump and not is_pressing_jump and not elytra.active is_pressing_jump = control.jump if is_just_jumped and not elytra.active then - elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 20) + elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 2) end -- don't let player get too fast by spamming jump local block_below = minetest.get_node(vector.offset(player:get_velocity(), 0, -0.7, 0)).name @@ -353,9 +353,10 @@ minetest.register_globalstep(function(dtime) -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player player_vel = vector.multiply(player_vel, -0.1) + if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end new_vel = vector.add(new_vel, player_vel) - new_vel.y = new_vel.y - (200 / math.max(speed_mult*10, 2)) * dtime + new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) else From b7a5a74ccf349f869f3f2d643efea0b03a31635a Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 3 Aug 2022 00:14:31 +1000 Subject: [PATCH 21/36] less pitch up slowdown --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index cf8eafc2e..ae346b75e 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -308,7 +308,7 @@ minetest.register_globalstep(function(dtime) local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) local direction_mult = clamp(-direction.y - 0.2, -0.8, 1) - if direction_mult < 0 then direction_mult = -(direction_mult^2) / 2 end + if direction_mult < 0 then direction_mult = -(direction_mult^2) / 4 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down From 4df51bac7291adb533a85a5440781cffda6a0add Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 3 Aug 2022 01:03:28 +1000 Subject: [PATCH 22/36] code quality, minor tweaks --- mods/PLAYER/mcl_playerplus/init.lua | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index ae346b75e..1c7c44532 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -302,13 +302,13 @@ minetest.register_globalstep(function(dtime) mcl_player.player_set_animation(player, "fly") local slowdown_mult = 0.2 -- amount of vel to take per sec local fall_speed = 20 -- amount to fall down per sec in nodes - local speedup_mult = 5 -- amount of speed to add based on look dir + local speedup_mult = 7 -- amount of speed to add based on look dir local max_speed = 100 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) local direction_mult = clamp(-direction.y - 0.2, -0.8, 1) - if direction_mult < 0 then direction_mult = -(direction_mult^2) / 4 end + if direction_mult < 0 then direction_mult = -(direction_mult^2) / 2 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down @@ -318,16 +318,12 @@ minetest.register_globalstep(function(dtime) speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*3))) end - elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it - new_vel = direction -- use the facing direction as a base - playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) if elytra.rocketing > 0 then elytra.rocketing = elytra.rocketing - dtime if vector.length(player_velocity) < 40 then -- player:add_velocity(vector.multiply(player:get_look_dir(), 4)) speed_mult = 10 - elytra.speed = speed_mult add_particle({ pos = fly_pos, velocity = {x = 0, y = 0, z = 0}, @@ -342,21 +338,19 @@ minetest.register_globalstep(function(dtime) end end + elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it + + local new_vel = direction -- use the facing direction as a base new_vel = vector.multiply(new_vel, speed_mult) - new_vel = { - x = clamp(new_vel.x, -max_speed, max_speed), - y = clamp(new_vel.y, -max_speed, max_speed), - z = clamp(new_vel.z, -max_speed, max_speed)} - -- new_vel = vector.multiply(new_vel, dtime * 30) -- slow the player down so less spongy movement by applying half the inverse vel - -- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken + -- NOTE: do not set this higher than about 0.2 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player player_vel = vector.multiply(player_vel, -0.1) if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end new_vel = vector.add(new_vel, player_vel) - new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) + -- new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) new_vel.y = new_vel.y - fall_speed * dtime player:add_velocity(new_vel) else From 3c0992e58dfb5ab1e42807c93bb835c22aa4e976 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 3 Aug 2022 18:41:51 +1000 Subject: [PATCH 23/36] tweaks --- mods/PLAYER/mcl_playerplus/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 1c7c44532..48504f22b 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -300,15 +300,15 @@ minetest.register_globalstep(function(dtime) player:set_pos(vector.offset(player:get_pos(), 0, 0.8, 0)) end mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 0.2 -- amount of vel to take per sec - local fall_speed = 20 -- amount to fall down per sec in nodes + local slowdown_mult = 0 -- amount of vel to take per sec + local fall_speed = 40 -- amount to fall down per sec in nodes local speedup_mult = 7 -- amount of speed to add based on look dir local max_speed = 100 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-direction.y - 0.2, -0.8, 1) - if direction_mult < 0 then direction_mult = -(direction_mult^2) / 2 end + local direction_mult = clamp(-direction.y - 0.1, -0.8, 1) + if direction_mult < 0 then direction_mult = -((direction_mult*2)^2) / 6 end local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime speed_mult = speed_mult - slowdown_mult * dtime -- slow down @@ -347,7 +347,7 @@ minetest.register_globalstep(function(dtime) -- NOTE: do not set this higher than about 0.2 or the game will get the wrong vel and it will be broken -- this is far from ideal, but there's no good way to set_velocity on the player player_vel = vector.multiply(player_vel, -0.1) - if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end + -- if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end new_vel = vector.add(new_vel, player_vel) -- new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) From cd6da88b3791ac6d7dfee3f0aababc8dfd21fa43 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 5 Aug 2022 14:43:48 +1000 Subject: [PATCH 24/36] tweaks again --- mods/PLAYER/mcl_playerplus/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 48504f22b..1a6bafb5c 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -301,7 +301,7 @@ minetest.register_globalstep(function(dtime) end mcl_player.player_set_animation(player, "fly") local slowdown_mult = 0 -- amount of vel to take per sec - local fall_speed = 40 -- amount to fall down per sec in nodes + local fall_speed = 20 -- amount to fall down per sec in nodes local speedup_mult = 7 -- amount of speed to add based on look dir local max_speed = 100 local direction = player:get_look_dir() @@ -315,10 +315,10 @@ minetest.register_globalstep(function(dtime) speed_mult = math.max(speed_mult, -1) speed_mult = math.min(speed_mult, max_speed) if turn_amount > 0.3 then - speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*3))) + speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*8))) end - playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) + playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.01) if elytra.rocketing > 0 then elytra.rocketing = elytra.rocketing - dtime if vector.length(player_velocity) < 40 then From 1263c43b5d83e21d4b14637c236447f6fcd80cba Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sat, 6 Aug 2022 14:38:42 +1000 Subject: [PATCH 25/36] elytra and other non-combat armour don't take durability damage when the player is attacked --- mods/ITEMS/mcl_armor/damage.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua index ed616397d..ad0db64bf 100644 --- a/mods/ITEMS/mcl_armor/damage.lua +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -33,7 +33,7 @@ mcl_damage.register_modifier(function(obj, damage, reason) local itemname = itemstack:get_name() local enchantments = mcl_enchanting.get_enchantments(itemstack) - if not flags.bypasses_armor then + if not flags.bypasses_armor and minetest.get_item_group(itemname, "non_combat_armor") == 0 then points = points + minetest.get_item_group(itemname, "mcl_armor_points") toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness") From 509fadfebb90c5f0b8571cc20d732f3a425c1f54 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 7 Aug 2022 00:38:20 +1000 Subject: [PATCH 26/36] fix is_pressing_jump being global --- mods/PLAYER/mcl_playerplus/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 1a6bafb5c..fb630c9e7 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -1,8 +1,8 @@ mcl_playerplus = { elytra = {}, + is_pressing_jump = {}, } -local is_pressing_jump = false local get_connected_players = minetest.get_connected_players local dir_to_yaw = minetest.dir_to_yaw local get_item_group = minetest.get_item_group @@ -279,8 +279,8 @@ minetest.register_globalstep(function(dtime) elytra.speed = 2 end - local is_just_jumped = control.jump and not is_pressing_jump and not elytra.active - is_pressing_jump = control.jump + local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active + mcl_playerplus.is_pressing_jump[name] = control.jump if is_just_jumped and not elytra.active then elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 2) end From 02c92dc6f85ba463a01140618afc3d1fcb1ace07 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 7 Aug 2022 01:05:39 +1000 Subject: [PATCH 27/36] fix getting wrong node --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index fb630c9e7..d662c4fb8 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -285,7 +285,7 @@ minetest.register_globalstep(function(dtime) elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 2) end -- don't let player get too fast by spamming jump - local block_below = minetest.get_node(vector.offset(player:get_velocity(), 0, -0.7, 0)).name + local block_below = minetest.get_node(vector.offset(player:get_pos(), 0, -0.7, 0)).name if minetest.registered_nodes[block_below].walkable then elytra.speed = clamp(elytra.speed, -1, 5) end From 5a8216ba43f85c06cc78c736e1a718147e83f905 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 7 Aug 2022 23:12:57 +1000 Subject: [PATCH 28/36] moved functions and constants out of global step (oops) --- mods/PLAYER/mcl_playerplus/init.lua | 43 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index d662c4fb8..d1fa68591 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -214,6 +214,24 @@ local function set_bone_position_conditional(player,b,p,r) --bone,position,rotat player:set_bone_position(b,p,r) end +local function get_overall_velocity(vector) + local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2) + return v +end +local function anglediff(a1, a2) + local a = a1 - a2 + return math.abs((a + math.pi) % (math.pi*2) - math.pi) +end +local function clamp(num, min, max) + return math.min(max, math.max(num, min)) +end + +local elytra_vars = { + slowdown_mult = 0, -- amount of vel to take per sec + fall_speed = 20, -- amount to fall down per sec in nodes + speedup_mult = 7, -- amount of speed to add based on look dir + max_speed = 100, -- max amount to multiply against look direction when flying +} minetest.register_globalstep(function(dtime) @@ -262,19 +280,6 @@ minetest.register_globalstep(function(dtime) local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.05, z = fly_pos.z}).name local elytra = mcl_playerplus.elytra[player] - local function get_overall_velocity(vector) - local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2) - return v - end - local function anglediff(a1, a2) - local a = a1 - a2 - return math.abs((a + math.pi) % (math.pi*2) - math.pi) - end - - local function clamp(num, min, max) - return math.min(max, math.max(num, min)) - end - if not elytra.active then elytra.speed = 2 end @@ -300,20 +305,16 @@ minetest.register_globalstep(function(dtime) player:set_pos(vector.offset(player:get_pos(), 0, 0.8, 0)) end mcl_player.player_set_animation(player, "fly") - local slowdown_mult = 0 -- amount of vel to take per sec - local fall_speed = 20 -- amount to fall down per sec in nodes - local speedup_mult = 7 -- amount of speed to add based on look dir - local max_speed = 100 local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) local direction_mult = clamp(-direction.y - 0.1, -0.8, 1) if direction_mult < 0 then direction_mult = -((direction_mult*2)^2) / 6 end - local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime - speed_mult = speed_mult - slowdown_mult * dtime -- slow down + local speed_mult = elytra.speed + direction_mult * elytra_vars.speedup_mult * dtime + speed_mult = speed_mult - elytra_vars.slowdown_mult * dtime -- slow down speed_mult = math.max(speed_mult, -1) - speed_mult = math.min(speed_mult, max_speed) + speed_mult = math.min(speed_mult, elytra_vars.max_speed) if turn_amount > 0.3 then speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*8))) end @@ -351,7 +352,7 @@ minetest.register_globalstep(function(dtime) new_vel = vector.add(new_vel, player_vel) -- new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) - new_vel.y = new_vel.y - fall_speed * dtime + new_vel.y = new_vel.y - elytra_vars.fall_speed * dtime player:add_velocity(new_vel) else elytra.rocketing = 0 From 9fdcfcd89864572f7ee20fbe6d949da9f8d901d3 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 8 Aug 2022 00:05:00 +1000 Subject: [PATCH 29/36] significanltly more accurate values, much slower, more reliable physics, more comments --- mods/PLAYER/mcl_playerplus/init.lua | 35 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index d1fa68591..8ea73f17c 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -227,10 +227,12 @@ local function clamp(num, min, max) end local elytra_vars = { - slowdown_mult = 0, -- amount of vel to take per sec - fall_speed = 20, -- amount to fall down per sec in nodes - speedup_mult = 7, -- amount of speed to add based on look dir - max_speed = 100, -- max amount to multiply against look direction when flying + slowdown_mult = 0.05, -- amount of vel to take per sec + fall_speed = 1, -- amount of vel to fall down per sec + speedup_mult = 3, -- amount of speed to add based on look dir + max_speed = 30, -- max amount to multiply against look direction when flying + pitch_penalty = 0.8, -- if pitching up, slow down at this rate as a multiplier + rocket_speed = 5, } @@ -308,23 +310,22 @@ minetest.register_globalstep(function(dtime) local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-direction.y - 0.1, -0.8, 1) - if direction_mult < 0 then direction_mult = -((direction_mult*2)^2) / 6 end + local direction_mult = clamp(-(direction.y), -1, 1) + if direction_mult < 0 then direction_mult = direction_mult * elytra_vars.pitch_penalty end local speed_mult = elytra.speed + direction_mult * elytra_vars.speedup_mult * dtime speed_mult = speed_mult - elytra_vars.slowdown_mult * dtime -- slow down - speed_mult = math.max(speed_mult, -1) - speed_mult = math.min(speed_mult, elytra_vars.max_speed) - if turn_amount > 0.3 then + speed_mult = clamp(speed_mult, -elytra_vars.max_speed, elytra_vars.max_speed) + if turn_amount > 0.3 and math.abs(direction.y) < 0.98 then -- don't do this if looking straight up / down speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*8))) end - playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.01) + playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", elytra_vars.fall_speed) if elytra.rocketing > 0 then elytra.rocketing = elytra.rocketing - dtime if vector.length(player_velocity) < 40 then -- player:add_velocity(vector.multiply(player:get_look_dir(), 4)) - speed_mult = 10 + speed_mult = elytra_vars.rocket_speed add_particle({ pos = fly_pos, velocity = {x = 0, y = 0, z = 0}, @@ -341,20 +342,18 @@ minetest.register_globalstep(function(dtime) elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it - local new_vel = direction -- use the facing direction as a base - new_vel = vector.multiply(new_vel, speed_mult) + local new_vel = vector.multiply(direction, speed_mult) -- use the look dir and speed as a mult + -- new_vel.y = new_vel.y - elytra_vars.fall_speed * dtime -- make the player fall a set amount - -- slow the player down so less spongy movement by applying half the inverse vel + -- slow the player down so less spongy movement by applying some of the inverse velocity -- NOTE: do not set this higher than about 0.2 or the game will get the wrong vel and it will be broken - -- this is far from ideal, but there's no good way to set_velocity on the player + -- this is far from ideal, but there's no good way to set_velocity or slow down the player player_vel = vector.multiply(player_vel, -0.1) -- if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end new_vel = vector.add(new_vel, player_vel) - -- new_vel.y = new_vel.y + clamp(speed_mult * dtime * 10, -10, 0) - new_vel.y = new_vel.y - elytra_vars.fall_speed * dtime player:add_velocity(new_vel) - else + else -- reset things when you stop flying with elytra elytra.rocketing = 0 playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end From 99eca2ceb92b0d6966e147f3f6c7d5d517ca769b Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 8 Aug 2022 02:05:03 +1000 Subject: [PATCH 30/36] player will not be upside down when flying or swimming --- mods/PLAYER/mcl_playerplus/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 8ea73f17c..6efca4856 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -406,7 +406,7 @@ minetest.register_globalstep(function(dtime) -- sets eye height, and nametag color accordingly set_properties_conditional(player,{collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when flying - set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) + set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new((75-degrees(dir_to_pitch(player_velocity))) , -player_vel_yaw + yaw, 0)) elseif parent then local parent_yaw = degrees(parent:get_yaw()) set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) @@ -422,11 +422,11 @@ minetest.register_globalstep(function(dtime) elseif get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and is_sprinting(name) == true then -- set head pitch and yaw when swimming is_swimming = true - set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch-degrees(dir_to_pitch(player_velocity)),player_vel_yaw - yaw,0)) + set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch-degrees(dir_to_pitch(player_velocity))+20,player_vel_yaw - yaw,0)) -- sets eye height, and nametag color accordingly set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming - set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) + set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new((75-degrees(dir_to_pitch(player_velocity))) , -player_vel_yaw + yaw, 0)) elseif get_item_group(mcl_playerinfo[name].node_head, "opaque") == 0 and get_item_group(mcl_playerinfo[name].node_head_top, "opaque") == 0 then -- sets eye height, and nametag color accordingly From 45c93e034076d10a87df2250d7915af8c4a45cef Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 8 Aug 2022 10:50:06 +1000 Subject: [PATCH 31/36] accurater physics, can't spam jump to gain speed on flat ground (needs work to allow mc like boosting) --- mods/PLAYER/mcl_playerplus/init.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 6efca4856..4075b9372 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -228,10 +228,10 @@ end local elytra_vars = { slowdown_mult = 0.05, -- amount of vel to take per sec - fall_speed = 1, -- amount of vel to fall down per sec - speedup_mult = 3, -- amount of speed to add based on look dir + fall_speed = 0.3, -- amount of vel to fall down per sec + speedup_mult = 2, -- amount of speed to add based on look dir max_speed = 30, -- max amount to multiply against look direction when flying - pitch_penalty = 0.8, -- if pitching up, slow down at this rate as a multiplier + pitch_penalty = 1.3, -- if pitching up, slow down at this rate as a multiplier rocket_speed = 5, } @@ -289,12 +289,14 @@ minetest.register_globalstep(function(dtime) local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active mcl_playerplus.is_pressing_jump[name] = control.jump if is_just_jumped and not elytra.active then - elytra.speed = clamp(get_overall_velocity(player:get_velocity()) - 1, 0, 2) - end - -- don't let player get too fast by spamming jump - local block_below = minetest.get_node(vector.offset(player:get_pos(), 0, -0.7, 0)).name - if minetest.registered_nodes[block_below].walkable then - elytra.speed = clamp(elytra.speed, -1, 5) + elytra.speed = clamp(get_overall_velocity(player:get_velocity()), 1, 5) + -- don't let player get too fast by spamming jump + local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name + local block_below2 = minetest.get_node(vector.offset(fly_pos, 0, -1.9, 0)).name + if minetest.registered_nodes[block_below].walkable + or minetest.registered_nodes[block_below2].walkable then + elytra.speed = 1.5 + end end elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" @@ -310,7 +312,7 @@ minetest.register_globalstep(function(dtime) local direction = player:get_look_dir() local player_vel = player:get_velocity() local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel)) - local direction_mult = clamp(-(direction.y), -1, 1) + local direction_mult = clamp(-(direction.y+0.1), -1, 1) if direction_mult < 0 then direction_mult = direction_mult * elytra_vars.pitch_penalty end local speed_mult = elytra.speed + direction_mult * elytra_vars.speedup_mult * dtime From dd9c8b3f48e5a687c5b7bb5a6c95c35c0a9ab4b6 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Mon, 8 Aug 2022 11:50:23 +1000 Subject: [PATCH 32/36] more accurate physics again, prevent slow servers having slower flight --- mods/PLAYER/mcl_playerplus/init.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 4075b9372..5bd369d2b 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -227,12 +227,12 @@ local function clamp(num, min, max) end local elytra_vars = { - slowdown_mult = 0.05, -- amount of vel to take per sec - fall_speed = 0.3, -- amount of vel to fall down per sec - speedup_mult = 2, -- amount of speed to add based on look dir - max_speed = 30, -- max amount to multiply against look direction when flying + slowdown_mult = 0.0, -- amount of vel to take per sec + fall_speed = 0.2, -- amount of vel to fall down per sec + speedup_mult = 4, -- amount of speed to add based on look dir + max_speed = 6, -- max amount to multiply against look direction when flying pitch_penalty = 1.3, -- if pitching up, slow down at this rate as a multiplier - rocket_speed = 5, + rocket_speed = 5.5, } @@ -316,7 +316,7 @@ minetest.register_globalstep(function(dtime) if direction_mult < 0 then direction_mult = direction_mult * elytra_vars.pitch_penalty end local speed_mult = elytra.speed + direction_mult * elytra_vars.speedup_mult * dtime - speed_mult = speed_mult - elytra_vars.slowdown_mult * dtime -- slow down + speed_mult = speed_mult - elytra_vars.slowdown_mult * clamp(dtime, 0.09, 0.2) -- slow down but don't overdo it speed_mult = clamp(speed_mult, -elytra_vars.max_speed, elytra_vars.max_speed) if turn_amount > 0.3 and math.abs(direction.y) < 0.98 then -- don't do this if looking straight up / down speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*8))) @@ -344,7 +344,7 @@ minetest.register_globalstep(function(dtime) elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it - local new_vel = vector.multiply(direction, speed_mult) -- use the look dir and speed as a mult + local new_vel = vector.multiply(direction, speed_mult * dtime * 30) -- use the look dir and speed as a mult -- new_vel.y = new_vel.y - elytra_vars.fall_speed * dtime -- make the player fall a set amount -- slow the player down so less spongy movement by applying some of the inverse velocity From 25491b3882edccb80ad67fbdf328a2f8ecfdabf5 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Wed, 10 Aug 2022 13:24:08 +1000 Subject: [PATCH 33/36] prevent player from gaining too much speed by pitching down and spamming jump --- mods/PLAYER/mcl_playerplus/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 5bd369d2b..5d6d23dec 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -283,7 +283,7 @@ minetest.register_globalstep(function(dtime) local elytra = mcl_playerplus.elytra[player] if not elytra.active then - elytra.speed = 2 + elytra.speed = 0 end local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active @@ -295,7 +295,7 @@ minetest.register_globalstep(function(dtime) local block_below2 = minetest.get_node(vector.offset(fly_pos, 0, -1.9, 0)).name if minetest.registered_nodes[block_below].walkable or minetest.registered_nodes[block_below2].walkable then - elytra.speed = 1.5 + elytra.speed = 1 end end From 97472becfc4288efabfcd74d9b49c771faf6a3f2 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 12 Aug 2022 02:26:22 +1000 Subject: [PATCH 34/36] I'm over it. --- mods/PLAYER/mcl_playerplus/init.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 5d6d23dec..4975f9eab 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -229,7 +229,7 @@ end local elytra_vars = { slowdown_mult = 0.0, -- amount of vel to take per sec fall_speed = 0.2, -- amount of vel to fall down per sec - speedup_mult = 4, -- amount of speed to add based on look dir + speedup_mult = 2, -- amount of speed to add based on look dir max_speed = 6, -- max amount to multiply against look direction when flying pitch_penalty = 1.3, -- if pitching up, slow down at this rate as a multiplier rocket_speed = 5.5, @@ -279,7 +279,7 @@ minetest.register_globalstep(function(dtime) player_vel_yaws[name] = player_vel_yaw local fly_pos = player:get_pos() - local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.05, z = fly_pos.z}).name + local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.1, z = fly_pos.z}).name local elytra = mcl_playerplus.elytra[player] if not elytra.active then @@ -289,7 +289,7 @@ minetest.register_globalstep(function(dtime) local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active mcl_playerplus.is_pressing_jump[name] = control.jump if is_just_jumped and not elytra.active then - elytra.speed = clamp(get_overall_velocity(player:get_velocity()), 1, 5) + elytra.speed = clamp(get_overall_velocity(player:get_velocity()), 1, 3) -- don't let player get too fast by spamming jump local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name local block_below2 = minetest.get_node(vector.offset(fly_pos, 0, -1.9, 0)).name @@ -302,7 +302,7 @@ minetest.register_globalstep(function(dtime) elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and not player:get_attach() and (elytra.active or (is_just_jumped and player_velocity.y < -0)) - and (fly_node == "air" or fly_node == "ignore") + and ((not minetest.registered_nodes[fly_node].walkable) or fly_node == "ignore") if elytra.active then if is_just_jumped then -- move the player up when they start flying to give some clearance @@ -315,7 +315,11 @@ minetest.register_globalstep(function(dtime) local direction_mult = clamp(-(direction.y+0.1), -1, 1) if direction_mult < 0 then direction_mult = direction_mult * elytra_vars.pitch_penalty end - local speed_mult = elytra.speed + direction_mult * elytra_vars.speedup_mult * dtime + local speed_mult = elytra.speed + local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name + if (not minetest.registered_nodes[block_below].walkable) and (player_vel.y ~= 0) then + speed_mult = speed_mult + direction_mult * elytra_vars.speedup_mult * dtime + end speed_mult = speed_mult - elytra_vars.slowdown_mult * clamp(dtime, 0.09, 0.2) -- slow down but don't overdo it speed_mult = clamp(speed_mult, -elytra_vars.max_speed, elytra_vars.max_speed) if turn_amount > 0.3 and math.abs(direction.y) < 0.98 then -- don't do this if looking straight up / down From 6cab000b2a60d03d033ace76a96b689fa5a975bc Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 12 Aug 2022 12:57:21 +1000 Subject: [PATCH 35/36] fix merge conflict --- mods/PLAYER/mcl_playerplus/init.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 0d24b9a86..d8217ece8 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -432,15 +432,9 @@ minetest.register_globalstep(function(dtime) -- sets eye height, and nametag color accordingly set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming -<<<<<<< HEAD set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new((75-degrees(dir_to_pitch(player_velocity))) , -player_vel_yaw + yaw, 0)) - elseif get_item_group(mcl_playerinfo[name].node_head, "opaque") == 0 - and get_item_group(mcl_playerinfo[name].node_head_top, "opaque") == 0 then -======= - set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) elseif get_item_group(mcl_playerinfo[name].node_head, "solid") == 0 and get_item_group(mcl_playerinfo[name].node_head_top, "solid") == 0 then ->>>>>>> master -- sets eye height, and nametag color accordingly is_swimming = false set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) From 307140b9a462f895210e1f1329ae16376b1e4e7b Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 12 Aug 2022 13:03:11 +1000 Subject: [PATCH 36/36] still over it --- mods/PLAYER/mcl_playerplus/init.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index d8217ece8..8756846ce 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -289,14 +289,8 @@ minetest.register_globalstep(function(dtime) local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active mcl_playerplus.is_pressing_jump[name] = control.jump if is_just_jumped and not elytra.active then - elytra.speed = clamp(get_overall_velocity(player:get_velocity()), 1, 3) - -- don't let player get too fast by spamming jump - local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name - local block_below2 = minetest.get_node(vector.offset(fly_pos, 0, -1.9, 0)).name - if minetest.registered_nodes[block_below].walkable - or minetest.registered_nodes[block_below2].walkable then - elytra.speed = 1 - end + local direction = player:get_look_dir() + elytra.speed = 1 - (direction.y/2 + 0.5) end elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra"