Increase off-rail friction, make off-rail carts shake, remove debug print

This commit is contained in:
teknomunk 2024-11-12 06:22:08 -06:00 committed by the-real-herowl
parent 6f5760000e
commit ddb70e5ebf
3 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)