- if dir.x ~= 0 and dir2.z ~= 0 then
- --local inertia = math.abs(self.object:get_velocity().x)
- local inertia = math.abs(self.velocity.x)
- --self.object:set_velocity(vector.multiply(dir2,inertia))
-
- self.velocity = vector.multiply(dir2,inertia)
- self.dir = dir2
- self.axis_lock = "z"
- self.object:set_pos(pos)
- direction_snap(self)
- return(true)
- elseif dir.z ~= 0 and dir2.x ~= 0 then
- --local inertia = math.abs(self.object:get_velocity().z)
- --print(dump(self.velocity))
- local inertia = math.abs(self.velocity.z)
- --self.object:set_velocity(vector.multiply(dir2,inertia))
-
- self.velocity = vector.multiply(dir2,inertia)
+ if self.axis_lock == "x" then
+ if dir.x ~= 0 and dir2.z ~= 0 then
+ local velocity = self.object:get_velocity()
+ local inertia = math.abs(velocity.x)
+ self.object:set_velocity(vector.multiply(dir2,inertia))
+ self.dir = dir2
+ self.axis_lock = "z"
+ self.object:set_pos(pos)
+ direction_snap(self)
+ return(true)
+ end
+ end
+ if self.axis_lock == "z" then
+ if dir.z ~= 0 and dir2.x ~= 0 then
+ local velocity = self.object:get_velocity()
+ local inertia = math.abs(velocity.z)
+ self.object:set_velocity(vector.multiply(dir2,inertia))
+ self.dir = dir2
+ self.axis_lock = "x"
+ self.object:set_pos(pos)
+ direction_snap(self)
+ return(true)
+ end
+ end
+ return(false)
+end
+
+local function climb_snap(pos,self,dir,dir2)
+ if self.axis_lock == "x" then
+ if dir.x == dir2.x and dir2.y ~= 0 then
+ local velocity = self.object:get_velocity()
+ local inertia = math.abs(velocity.x)
+ self.object:set_velocity(vector.multiply(dir2,inertia))
+ self.dir = dir2
+ self.axis_lock = "x"
+ self.object:set_pos(pos)
+ direction_snap(self)
+ return(true)
+ end
+ end
+ if self.axis_lock == "z" then
+ if dir.z == dir2.z and dir2.y ~= 0 then
+ local velocity = self.object:get_velocity()
+ local inertia = math.abs(velocity.z)
+ self.object:set_velocity(vector.multiply(dir2,inertia))
+ self.dir = dir2
+ self.axis_lock = "z"
+ self.object:set_pos(pos)
+ direction_snap(self)
+ return(true)
+ end
+ end
+ return(false)
+end
+
+local function straight_snap(pos,self,dir)
+ if self.axis_lock == "x" then
+ if dir.x ~= 0 and pool[minetest.hash_node_position(vector.add(pos,vector.new(dir.x,0,0)))] then
+ local velocity = self.object:get_velocity()
+ self.object:set_velocity(vector.new(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)
+ end
+ end
+ if self.axis_lock == "z" then
+ if dir.z ~= 0 and pool[minetest.hash_node_position(vector.add(pos,vector.new(0,0,dir.z)))] then
+ local velocity = self.object:get_velocity()
+ self.object:set_velocity(vector.new(0,0,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
+ return(false)
+end
+
+
+local function coupling_logic(self)
+
+ if not self.axis_lock then return end
+
+ if not self.coupler1 then return end