Remove unused vector.floor, check if cart is centered on rail

Fix cart wiggle/swing partwise
Simplify the curve velocity calculations
This commit is contained in:
SmallJoker 2016-11-19 19:37:13 +01:00
parent 75132269d7
commit 74d8b8f931
1 changed files with 17 additions and 25 deletions

View File

@ -13,14 +13,6 @@ if not boost_cart.modpath then
"See also: http://dev.minetest.net/Installing_Mods") "See also: http://dev.minetest.net/Installing_Mods")
end end
function vector.floor(v)
return {
x = math.floor(v.x),
y = math.floor(v.y),
z = math.floor(v.z)
}
end
dofile(boost_cart.modpath.."/functions.lua") dofile(boost_cart.modpath.."/functions.lua")
dofile(boost_cart.modpath.."/rails.lua") dofile(boost_cart.modpath.."/rails.lua")
@ -195,7 +187,7 @@ function boost_cart.cart:on_step(dtime)
if not found_path then if not found_path then
-- No rail found: reset back to the expected position -- No rail found: reset back to the expected position
pos = expected_pos pos = vector.new(self.old_pos)
update.pos = true update.pos = true
end end
end end
@ -215,23 +207,22 @@ function boost_cart.cart:on_step(dtime)
update.pos = true update.pos = true
update.vel = true update.vel = true
else else
-- If the direction changed -- Direction change detected
if dir.x ~= 0 and self.old_dir.z ~= 0 then if not vector.equals(dir, self.old_dir) then
vel.x = dir.x * math.abs(vel.z) vel = vector.multiply(dir, math.abs(vel.x + vel.z))
vel.z = 0 update.vel = true
pos.z = math.floor(pos.z + 0.5) if dir.y ~= self.old_dir.y then
update.pos = true pos = vector.round(pos)
update.pos = true
end
end end
if dir.z ~= 0 and self.old_dir.x ~= 0 then -- Center on the rail
vel.z = dir.z * math.abs(vel.x) if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then
vel.x = 0
pos.x = math.floor(pos.x + 0.5) pos.x = math.floor(pos.x + 0.5)
update.pos = true update.pos = true
end end
-- Up, down? if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then
if dir.y ~= self.old_dir.y then pos.z = math.floor(pos.z + 0.5)
vel.y = dir.y * math.abs(vel.x + vel.z)
pos = vector.round(pos)
update.pos = true update.pos = true
end end
@ -250,14 +241,15 @@ function boost_cart.cart:on_step(dtime)
-- Try to make it similar to the original carts mod -- Try to make it similar to the original carts mod
acc = acc + (speed_mod * 10) acc = acc + (speed_mod * 10)
else else
acc = acc - 0.4
-- Handbrake -- Handbrake
if ctrl and ctrl.down then if ctrl and ctrl.down then
acc = acc - 1.2 acc = acc - 1.6
else
acc = acc - 0.4
end end
end end
if self.old_dir.y == 0 and not self.punched then if self.old_dir.y ~= 1 and not self.punched then
-- Stop the cart swing between two rail parts (handbrake) -- Stop the cart swing between two rail parts (handbrake)
if vector.equals(vector.multiply(self.old_dir, -1), dir) then if vector.equals(vector.multiply(self.old_dir, -1), dir) then
vel = {x=0, y=0, z=0} vel = {x=0, y=0, z=0}