From 9c98588c3ac8cdfa33e44e39fe566b8c0f59faf4 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 4 May 2024 11:36:07 +0000 Subject: [PATCH] Make friction not apply in air, change how the two node physics accumulate --- mods/ENVIRONMENT/mcl_physics/init.lua | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_physics/init.lua b/mods/ENVIRONMENT/mcl_physics/init.lua index 93a10d0bc..44efbdc56 100644 --- a/mods/ENVIRONMENT/mcl_physics/init.lua +++ b/mods/ENVIRONMENT/mcl_physics/init.lua @@ -65,19 +65,36 @@ local function apply_node_physics(node, vel, staticdata, entity) local accel = vector.zero() -- Friction - local friction_scale = node_physics.friction - accel = accel + vel * -friction_scale + if node.name ~= "air" then + local friction_scale = node_physics.friction + accel = accel + vel * -friction_scale + end return vector.zero(), accel end mod.register_environment_effect(function(pos, vel, staticdata, entity) + local a = vector.zero() + local v = vector.zero() + + -- Apply node physics for the node we are inside of local pos1_r = vector.round(pos) - local v1,a1 = apply_node_physics(minetest.get_node(pos1_r), vel, staticdata, entity) + local node1 = minetest.get_node(pos1_r) + local v1,a1 = apply_node_physics(node1, vel, staticdata, entity) + v = v + v1 + a = a + a1 -- TODO: only apply when touching under_node local pos2_r = vector.offset(pos1_r,0,-1,0) - local v2,a2 = apply_node_physics(minetest.get_node(pos2_r), vel, staticdata, entity) + local node2 = minetest.get_node(pos2_r) + local v2,a2 = apply_node_physics(node2, vel, staticdata, entity) + v = v + v2 + a = a + a2 - return (v1 + v2), (a1 + a2) + -- Male speeds of less than 1/100 block/second count as zero + if vector.length(v) < 0.01 then + v = nil + end + + return v,a end)