Reset acceleration at speed limit

This commit is contained in:
SmallJoker 2018-07-07 15:23:30 +02:00
parent 34155473a9
commit d486143f42

View File

@ -229,7 +229,7 @@ function cart_entity:on_step(dtime)
) )
local dir_changed = not vector.equals(dir, self.old_dir) local dir_changed = not vector.equals(dir, self.old_dir)
local new_acc = {x=0, y=0, z=0} local acc = 0
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
vel = {x=0, y=0, z=0} vel = {x=0, y=0, z=0}
local pos_r = vector.round(pos) local pos_r = vector.round(pos)
@ -264,7 +264,7 @@ function cart_entity:on_step(dtime)
end end
-- Calculate current cart acceleration -- Calculate current cart acceleration
local acc = nil acc = nil
local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration") local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration")
if acc_meta == "halt" and not self.punched then if acc_meta == "halt" and not self.punched then
@ -306,21 +306,20 @@ function cart_entity:on_step(dtime)
else else
acc = 0 acc = 0
end end
new_acc = vector.multiply(dir, acc)
end end
-- Limits -- Limit cart speed
local max_vel = boost_cart.speed_max local vel_len = vector.length(vel)
for _,v in pairs({"x","y","z"}) do if vel_len > boost_cart.speed_max then
if math.abs(vel[v]) > max_vel then vel = vector.multiply(vel, boost_cart.speed_max / vel_len)
vel[v] = boost_cart:get_sign(vel[v]) * max_vel update.vel = true
new_acc[v] = 0 end
update.vel = true if vel_len >= boost_cart.speed_max and acc > 0 then
end acc = 0
end end
self.object:set_acceleration(new_acc) self.object:set_acceleration(vector.multiply(dir, acc))
self.old_pos = vector.round(pos) self.old_pos = vector.round(pos)
local old_y_dir = self.old_dir.y local old_y_dir = self.old_dir.y
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then