Krock wrote:The cart calculates its velocity each node, this means, it will decelerate and start moving backwards again (like it does on hills).
Yes, that was my problem, the cart would reverse direction instead of stopping.
- Adding a new meta int "cart_stop" to the new stop rail node
- Checking the meta value near init.lua line 219
- Changing acceleration `acc´ and velocity `vel´ array all to zero and the velocity update flag `update.vel´ to `true´ when the integer "cart_stop" equals 1
Did what you recommended, testing for hours with various variants of the code try to work out lua programming with the tutorials and looking at your mod and other mod's code.
Even with restarting minetest, removing the rails and building them anew I get different results. Sometimes it works: The cart will stop on the stop rail and start again (even in the right direction) when punching the mesecon button connected to the rails. But sometimes the cart will just slow down a bit and then accelerate again, passing the stop rail. :-/
I duplicated the power rail's code and texture, renamed the texture and changed it's color, and replaced parts of the code as follows:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.env:get_meta(pos):set_int("cart_stop", "1")
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
minetest.env:get_meta(pos):set_int("cart_stop", "0")
boost_cart:boost_rail(pos, 2)
end,
action_off = function(pos, node)
minetest.env:get_meta(pos):set_int("cart_stop", "1")
end,
},
},
I changed the rail and crafting definition, too. That seems to work, I can craft the stop rails and place them on the ground.
Here's the part in the init.lua I added (without the print commands for debug output):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local stop_mod = tonumber(minetest.get_meta(pos):get_int("cart_stop"))
if stop_mod and stop_mod >= 1 then
acc = 0
for _,v in ipairs({"x","y","z"}) do
vel[v] = 0
update.vel = true
end
end
But as I wrote sometimes it works, sometimes the cart won't stop even when the debug message tells me that the stop rail was detected and velocity set to 0.
The problem will be the cart starting. It does not know in which direction it was driving before -> valvulated by velocity.
However, also this can be solved by getting the
cart yaw and defining its direction that way.
Thanks, I will look into it as soon as I fixed stopping and starting the cart.