summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstujones11 <stujones111@gmail.com>2016-01-29 21:24:12 +0000
committerstujones11 <stujones111@gmail.com>2016-01-29 21:24:12 +0000
commit388f503e985b07022b72a98fb22f3ef19c2f7c6c (patch)
tree330c94a3501a2aae84016cc5a3cb5962870d7c26
parent99f5ffddfb603068249d1ac0b9682d8531213842 (diff)
Only check line-of-sight if object and target node are loaded
-rw-r--r--railcart/railcart.lua18
1 files changed, 11 insertions, 7 deletions
diff --git a/railcart/railcart.lua b/railcart/railcart.lua
index 6a3a22b..fbbad4a 100644
--- a/railcart/railcart.lua
+++ b/railcart/railcart.lua
@@ -299,13 +299,17 @@ function railcart:update(cart, time, object)
blocked = true
end
end
- local p1 = vector.add(cart.pos, {x=0, y=1, z=0})
- local p2 = vector.add(cart.target, {x=0, y=1, z=0})
- local los, bp = minetest.line_of_sight(p1, p2)
- if los == false then
- bp.y = bp.y - 1
- cart.target = vector.subtract(bp, cart.dir)
- blocked = true
+ if object then
+ local p1 = vector.add(cart.pos, {x=0, y=1, z=0})
+ local p2 = vector.add(cart.target, {x=0, y=1, z=0})
+ if minetest.get_node_or_nil(p2) then
+ local los, bp = minetest.line_of_sight(p1, p2)
+ if los == false then
+ bp.y = bp.y - 1
+ cart.target = vector.subtract(bp, cart.dir)
+ blocked = true
+ end
+ end
end
local d1 = railtrack:get_distance(cart.prev, cart.target)
local d2 = railtrack:get_distance(cart.prev, cart.pos)