From ddb70e5ebf34e9cc98a9cede7e8b74ffd9f5cd80 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 12 Nov 2024 06:22:08 -0600 Subject: [PATCH] Increase off-rail friction, make off-rail carts shake, remove debug print --- mods/ENTITIES/mcl_minecarts/carts.lua | 6 ------ mods/ENTITIES/mcl_minecarts/init.lua | 1 + mods/ENTITIES/mcl_minecarts/movement.lua | 17 +++++++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index 61cff7bb8..df77f6cf7 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -269,12 +269,6 @@ function DEFAULT_CART_DEF:on_punch(puncher, time_from_last_punch, tool_capabilit dir.y = 0 dir = vector.normalize(dir) local impulse = vector.dot(staticdata.dir, vector.multiply(dir, damage * 4)) - minetest.log(dump({ - dir = dir, - dir_len = vector.length(dir), - damage = damage, - impulse = impulse, - })) if impulse < 0 and staticdata.velocity == 0 then mod.reverse_direction(staticdata) impulse = -impulse diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 081e78314..55960e296 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -7,6 +7,7 @@ mcl_minecarts.modpath = modpath -- Constants mod.SPEED_MAX = 10 mod.FRICTION = 0.4 +mod.OFF_RAIL_FRICTION = 1.2 mod.MAX_TRAIN_LENGTH = 4 mod.CART_BLOCK_SIZE = 64 mod.PASSENGER_ATTACH_POSITION = vector.new(0, -1.75, 0) diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index 44ab1c535..aa1025a93 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -16,7 +16,8 @@ if minetest.get_modpath("mcl_physics") then elseif minetest.get_modpath("vl_physics") then env_physics = vl_physics end -local FRICTION = mcl_minecarts.FRICTION +local FRICTION = mod.FRICTION +local OFF_RAIL_FRICTION = mod.OFF_RAIL_FRICTION local MAX_TRAIN_LENGTH = mod.MAX_TRAIN_LENGTH local SPEED_MAX = mod.SPEED_MAX local train_length = mod.train_length @@ -524,18 +525,20 @@ function submod.do_movement( staticdata, dtime ) end end +local _half_pi = math.pi * 0.5 function submod.do_detached_movement(self, dtime) local staticdata = self._staticdata -- Make sure the object is still valid before trying to move it - if not self.object or not self.object:get_pos() then return end + local velocity = self.object:get_velocity() + if not self.object or not velocity then return end -- Apply physics if env_physics then env_physics.apply_entity_environmental_physics(self) else -- Simple physics - local friction = self.object:get_velocity() or vector.zero() + local friction = velocity or vector.zero() friction.y = 0 local accel = vector.new(0,-9.81,0) -- gravity @@ -543,15 +546,17 @@ function submod.do_detached_movement(self, dtime) -- Don't apply friction in the air local pos_rounded = vector.round(self.object:get_pos()) if minetest.get_node(vector.offset(pos_rounded,0,-1,0)).name ~= "air" then - accel = vector.add(accel, vector.multiply(friction,-0.9)) + accel = vector.add(accel, vector.multiply(friction,-OFF_RAIL_FRICTION)) end self.object:set_acceleration(accel) end - -- Reset pitch + -- Shake the cart (also resets pitch) local rot = self.object:get_rotation() - rot.y = 0 + local shake_amount = 0.05 * vector.length(velocity) + rot.x = (math.random() - 0.5) * shake_amount + rot.z = (math.random() - 0.5) * shake_amount self.object:set_rotation(rot) local away = vector_away_from_players(self, staticdata)