diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 45245622e3..1d67f5f725 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -4059,12 +4059,13 @@ local mob_step = function(self, dtime) -- end rotation if self.head_swivel and type(self.head_swivel) == "string" then + local final_rotation = vector.new(0,0,0) local oldp,oldr = self.object:get_bone_position(self.head_swivel) for _, obj in pairs(minetest.get_objects_inside_radius(pos, 10)) do if obj:is_player() and not self.attack or obj:get_luaentity() and obj:get_luaentity().name == self.name and self ~= obj:get_luaentity() then if not self._locked_object then - if math.random(5000/self.curiosity) == 1 then + if math.random(5000/self.curiosity) == 1 or vector.distance(pos,obj:get_pos())<4 and obj:is_player() then self._locked_object = obj end else @@ -4096,30 +4097,36 @@ local mob_step = function(self, dtime) local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0))) local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))+self.head_yaw_offset local mob_pitch = math.deg(-dir_to_pitch(direction_player))*self.head_pitch_multiplier - if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.type == "monster") then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9)) - elseif self.attack and self.type == "monster" then + + if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.state == "attack") then + final_rotation = vector.multiply(oldr, 0.9) + elseif self.attack and self.state == "attack" then if self.head_yaw == "y" then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, mob_yaw, 0)) + final_rotation = vector.new(mob_pitch, mob_yaw, 0) elseif self.head_yaw == "z" then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, 0, -mob_yaw)) + final_rotation = vector.new(mob_pitch, 0, -mob_yaw) end + else + if self.head_yaw == "y" then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0)) + final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0) elseif self.head_yaw == "z" then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3)) + final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3) end end end elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9)) + final_rotation = vector.multiply(oldr, 0.9) else - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(0,0,0)) + final_rotation = vector.new(0,0,0) end + mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), final_rotation) + end + -- run custom function (defined in mob lua file) if self.do_custom then