]> git.lizzy.rs Git - Crafter.git/commitdiff
Overhaul mob collision detection
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 03:57:55 +0000 (23:57 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 03:57:55 +0000 (23:57 -0400)
mods/mob/api/api_hook.lua
mods/mob/api/data_handling.lua
mods/mob/api/interaction.lua
mods/mob/init.lua

index e4733305572dab087d28e03811508bfdd1b877dc..6e58374ea47f1b81cae50e6bc77678699e516a29 100644 (file)
@@ -126,7 +126,7 @@ mob_register.custom_on_death = def.custom_on_death
 
 mob_register.mob = true
 
-mob_register.collision_boundary = def.collision_boundary or 1
+mob_register.custom_on_activate = def.custom_on_activate
 
 if def.pathfinds then
        --mob_register.path = {}
index f971f1af1c1c0fd6c6e130b9beb9e4ea0c649e37..80712d57023bca63adccbcfa298d18d6b686054d 100644 (file)
@@ -55,6 +55,9 @@ mobs.create_data_handling_functions = function(def,mob_register)
                end
                self.is_mob = true
                self.object:set_armor_groups({immortal = 1})
+               if self.custom_on_activate then
+                       self.custom_on_activate(self)
+               end
                --self.object:set_yaw(math.pi*math.random(-1,1)*math.random())
        end
 
index af057c04928fbdcf8ccdbdfe1e1381482a19aead..0ffbd10c70eda5022a5a4270263d11834a3dd934 100644 (file)
@@ -39,14 +39,46 @@ mobs.create_interaction_functions = function(def,mob_register)
        mob_register.collision_detection = function(self)
                local pos = self.object:get_pos()
                --do collision detection from the base of the mob
-               pos.y = pos.y - self.object:get_properties().collisionbox[2]
-               for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.collision_boundary*2)) do
-                       if object:is_player() or object:get_luaentity().mob == true then
+               
+               local collisionbox = self.object:get_properties().collisionbox
+
+               pos.y = pos.y + collisionbox[2]
+               
+               local collision_boundary = collisionbox[4]
+
+               local radius = collision_boundary
+
+               if collisionbox[5] > collision_boundary then
+                       radius = collisionbox[5]
+               end
+
+               for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius*1.25)) do
+                       if object ~= self.object and (object:is_player() or object:get_luaentity().mob == true) and
+                       --don't collide with rider, rider don't collide with thing
+                       (not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and 
+                       (not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then
+
                                local pos2 = object:get_pos()
                                
+                               local object_collisionbox = object:get_properties().collisionbox
+
+                               pos2.y = pos2.y + object_collisionbox[2]
+
+                               local object_collision_boundary = object_collisionbox[4]
+
+
+                               --this is checking the difference of the object collided with's possision
+                               --if positive top of other object is inside (y axis) of current object
+                               local y_base_diff = (pos2.y + object_collisionbox[5]) - pos.y
+
+                               local y_top_diff = (pos.y + collisionbox[5]) - pos2.y
+
+
+                               
+
                                local distance = vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
 
-                               if distance <= self.collision_boundary then
+                               if distance <= collision_boundary + object_collision_boundary and y_base_diff >= 0 and y_top_diff >= 0 then
 
                                        local dir = vector.direction(pos,pos2)
                                        dir.y = 0
index ed66485b60d623b7ed3a0c61a3db7e307326d88a..4779e6c5b4917569bfca50fbae17ebcc5fcbba6c 100644 (file)
@@ -302,7 +302,7 @@ mobs.register_mob(
        movement_type = "jump",
        make_jump_noise = true,
        max_speed = 5,
-       hostile = true,
+       hostile = false,
        state = 0,
        view_distance = 20,
        death_rotation = "z",
@@ -330,7 +330,6 @@ mobs.register_mob(
        textures = {
                "slime.png"
        },
-       collision_boundary = 1.25,
        is_visible = true,
        pointable = true,
        automatic_face_movement_dir = 90,
@@ -370,7 +369,6 @@ mobs.register_mob(
        textures = {
                "slime.png"
        },
-       collision_boundary = 0.6,
        is_visible = true,
        pointable = true,
        automatic_face_movement_dir = 90,
@@ -699,6 +697,12 @@ mobs.register_mob(
         attacked_hostile = true,
         attack_type = "punch",
         group_attack = true,
+
+        custom_on_activate = function(self)
+               local obj = minetest.add_entity(self.object:get_pos(),"mob:pig")
+               obj:set_attach(self.object,"",vector.new(0,3,0),vector.new(0,90,0))
+               obj:set_properties({visual_size={x=1,y=1}})
+        end
         --explosion_radius = 4, -- how far away the mob has to be to initialize the explosion
         --explosion_power = 7, -- how big the explosion has to be
         --explosion_time = 3, -- how long it takes for a mob to explode