]> git.lizzy.rs Git - Crafter.git/commitdiff
Make mobs pathfind even better
authoroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 25 May 2020 19:37:48 +0000 (15:37 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 25 May 2020 19:37:48 +0000 (15:37 -0400)
mods/mob/api/movement.lua
mods/mob/init.lua

index f92fb8c467360037f542ba10d3361d47c1e56a54..604c1aa35e88d928e824c9d15ea1a1f605208340 100644 (file)
@@ -188,13 +188,11 @@ mobs.create_movement_functions = function(def,mob_register)
                                        self.pathfinding_timer = 0
 
                                        local path = minetest.find_path(self.object:get_pos(),self.following_pos,self.view_distance*2,1,1,"A*")
-                                       if path then--or (self.path_data and table.getn(self.path_data) < 3)) then
+                                       
+                                       if path and not self.path_data or (self.path_data and table.getn(self.path_data) < 1) then
                                                self.path_data = path
                                        end
-                                       if self.path_data and table.getn(self.path_data) <= 4 then
-                                               self.path_data = nil
-                                       end
-
+                                       
                                        if self.path_data then
                                                for index,pos_data in pairs(self.path_data) do
                                                        --print(dump(pos_data))
@@ -209,9 +207,19 @@ mobs.create_movement_functions = function(def,mob_register)
                                                end
                                        end
                                end
+                       elseif not self.following then
+                               self.path_data = nil
                        end
+
+
+                       --this is the real time one
                        local selfpos = self.object:get_pos()
                        local pos1 = vector.new(selfpos.x,0,selfpos.z)
+
+                       if (self.path_data and table.getn(self.path_data) > 0 and vector.distance(self.object:get_pos(),self.path_data[1]) > 2) or self.swimming == true then
+                               self.path_data = nil
+                       end
+
                        if self.path_data and table.getn(self.path_data) > 0 and vector.distance(pos1,vector.new(self.path_data[1].x,0,self.path_data[1].z)) < 1 then
                                --shift whole list down
                                for i = 2,table.getn(self.path_data) do
index 6026a16b2865e867dde7180cbd4f0607b9f0e5e6..1e86526fad2acddd8555d26d5607a259d5474c45 100644 (file)
@@ -485,7 +485,7 @@ mobs.register_mob(
         hostile = true,
         hostile_cooldown = false,
         state = 0,
-        view_distance = 20,
+        view_distance = 40,
         item_drop = "mob:gunpowder",
          
         standing_frame = {x=0,y=0},
@@ -632,7 +632,7 @@ mobs.register_mob(
         movement_type = "walk",
         max_speed = 6,
         state = 0,
-        view_distance = 15,
+        view_distance = 45,
         
         item_drop = "mob:string", 
         standing_frame = {x=21,y=21},