From 6c54e91e1e773745abc581a77ae2870db08b0020 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sat, 4 Jul 2020 18:33:32 -0400 Subject: [PATCH] Add in abillity to scale hills --- mods/minecart/init.lua | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/mods/minecart/init.lua b/mods/minecart/init.lua index 97e8ea5..e9c806e 100644 --- a/mods/minecart/init.lua +++ b/mods/minecart/init.lua @@ -46,7 +46,6 @@ end local function collision_detect(self) if not self.axis_lock then return end local pos = self.object:get_pos() - for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do if object:is_player() then local pos2 = object:get_pos() @@ -93,6 +92,46 @@ local function turn_snap(pos,self,dir,dir2) end end +local function climb_snap(pos,self,dir,dir2) + if dir.x == dir2.x and dir2.y ~= 0 then + print(dump(dir2)) + print("x snapping") + local inertia = math.abs(self.velocity.x) + self.velocity = vector.multiply(dir2,inertia) + self.dir = dir2 + self.axis_lock = "x" + self.object:set_pos(pos) + direction_snap(self) + return(true) + elseif dir.z == dir2.z and dir2.y ~= 0 then + local inertia = math.abs(self.velocity.z) + self.velocity = vector.multiply(dir2,inertia) + self.dir = dir2 + self.axis_lock = "z" + self.object:set_pos(pos) + direction_snap(self) + return(true) + end +end + +local function straight_snap(pos,self,dir) + if dir.x ~= 0 and pool[minetest.hash_node_position(vector.add(pos,vector.new(dir.x,0,0)))] then + self.velocity = vector.new(self.velocity.x,0,0) + self.dir = vector.new(dir.x,0,0) + self.axis_lock = "x" + self.object:set_pos(pos) + direction_snap(self) + return(true) + elseif dir.z ~= 0 and pool[minetest.hash_node_position(vector.add(pos,vector.new(0,0,dir.z)))] then + self.velocity = vector.new(0,0,self.velocity.z) + self.dir = vector.new(0,0,dir.z) + self.axis_lock = "z" + self.object:set_pos(pos) + direction_snap(self) + return(true) + end +end + local function rail_brain(self,pos) if not self.dir then return end @@ -116,7 +155,13 @@ local function rail_brain(self,pos) --print(dump(dir)) if triggered and not pool[minetest.hash_node_position(vector.add(pos,dir))] then + + if straight_snap(pos,self,dir) then + return + end + local possible_dirs = create_axis(pos) + if table.getn(possible_dirs) == 0 then --print("train fails") --stop slow down become physical, something @@ -125,6 +170,9 @@ local function rail_brain(self,pos) if turn_snap(pos,self,dir,dir2) then return end + if climb_snap(pos,self,dir,dir2) then + return + end end end end -- 2.44.0