summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--railcart/init.lua4
-rw-r--r--railcart/railcart.lua5
2 files changed, 7 insertions, 2 deletions
diff --git a/railcart/init.lua b/railcart/init.lua
index 7ca7fe2..8d60051 100644
--- a/railcart/init.lua
+++ b/railcart/init.lua
@@ -165,12 +165,16 @@ minetest.register_craftitem("railcart:cart", {
return
end
end
+ local cons = railtrack:get_connections(pos)
local cart = railcart.cart:new()
cart.id = #railcart.allcarts + 1
cart.inv = railcart:create_detached_inventory(cart.id)
cart.pos = pos
cart.prev = vector.new(pos)
cart.accel = railtrack:get_acceleration(pos)
+ if cons[1] then
+ cart.target = cons[1]
+ end
table.insert(railcart.allcarts, cart)
railcart:save()
if not minetest.setting_getbool("creative_mode") then
diff --git a/railcart/railcart.lua b/railcart/railcart.lua
index 68174b6..655fffe 100644
--- a/railcart/railcart.lua
+++ b/railcart/railcart.lua
@@ -215,11 +215,12 @@ function railcart:update(cart, time, object)
end
end
local speed = railcart:velocity_to_speed(cart.vel)
- if not cart.target then
+ if cart.target then
+ cart.dir = railtrack:get_direction(cart.target, cart.pos)
+ else
speed = 0
end
if speed > RAILCART_SPEED_MIN then
- cart.dir = railtrack:get_direction(cart.target, cart.pos)
local d1 = railtrack:get_distance(cart.prev, cart.target)
local d2 = railtrack:get_distance(cart.prev, cart.pos)
local dist = d1 - d2