Pilzadam I was beginning to develop trains with your mod, while I'm on break I hope to see you develop the ability for minecarts to essentially be "attached" to eachother.
I was starting with a very simple code:
Replace this:
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 dir = cart_func:velocity_to_dir(self.velocity)
Which is in the on_step function of your carts with:
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
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 10)) do
if object:is_player() then
local objdir = object:getpos()
self.velocity.x = objdir.x - pos.x
self.velocity.z = objdir.z - pos.z
end
end
local dir = cart_func:velocity_to_dir(self.velocity)
This essentially makes the minecarts pathfind to a player through rails, this can be further heavily developed into attaching carts to eachother by right clicking with a special chain tool or something. You'd have to add another another self variable, which would be self.follow. But I did not get to that point yet. Let me explain further:
1.) A player right clicks the cart that should be the "lead" for the other cart with the tool.
2.) When the player clicks that cart, the luaentity should be stored in a table for that player's name.
3.) When the player clicks the "following" cart, it would be given the self variable (self.follow) of the luaentity it is supposed to follow.
4.) On step, if the luaentity it is supposed to follow is in it's radius (Maybe a radius of 5 or so) It would try to go towards that other cart.
5.) If it gets stopped, or disconnected (Someone breaks the rail in between them and the "lead" cart gets away) then the radius function should set the self.follow variable to nil or "" so that it will not try to follow the cart as if the connection between the "lead" and the "follow" broke.
Also, i have made a train out of your cart, it is very simple but it looks nice-ish. This train should get if the player is pushing the move forward key (w) and backwards key (s), and move forward, and stop/move backwards accordingly.
Here is a mesh that kaeza made:
http://pastebin.com/raw.php?i=5Wz8BqA5It is very simple and needs to be moved forward a bit so it appears that you are actually sitting in the train. I hope you can work with this information, as it will greatly help minetest achieve another awesome mod. Best of wishes. and merry Christmas.
If you can think it, you can make it.