From a2a06cc3ee89901e6ebbe8d84d29b03996f44f69 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Tue, 7 Jun 2022 11:38:38 -0700 Subject: [PATCH] Initial commit mobs head rotation --- mods/ENTITIES/mcl_mobs/api.lua | 45 ++++++++++++++++++ .../mobs_mc/models/mobs_mc_villager.b3d | Bin 67116 -> 71421 bytes mods/ENTITIES/mobs_mc/villager.lua | 4 ++ 3 files changed, 49 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 933634cce..5d1c91995 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -125,6 +125,14 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement end +local function dir_to_pitch(dir) + --local dir2 = vector.normalize(dir) + local xz = math.abs(dir.x) + math.abs(dir.z) + return -math.atan2(-dir.y, xz) +end + + + -- play sound local mob_sound = function(self, soundname, is_opinion, fixed_pitch) @@ -3644,6 +3652,41 @@ local mob_step = function(self, dtime) -- end rotation + if self.head_swivel and type(self.head_swivel) == "string" then + 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() then + if not self._locked_object then + if math.random(50) == 1 then + self._locked_object = obj + end + else + if math.random(200) == 1 then + self._locked_object = nil + end + end + end + end + + if self._locked_object then + local player_pos = self._locked_object:get_pos() + local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.bone_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, self._locked_object:get_properties().eye_height, 0))) + local mob_yaw = math.deg(-(-self.object:get_rotation().y-(-minetest.dir_to_yaw(direction_player)))) + local mob_pitch = math.deg(-dir_to_pitch(direction_player)) + if mob_yaw < -60 or mob_yaw > 60 then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.multiply(oldr, 0.9)) + else + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0)) + end + elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.multiply(oldr, 0.9)) + else + self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.new(0,0,0)) + end + + end + -- run custom function (defined in mob lua file) if self.do_custom then @@ -3883,6 +3926,8 @@ end minetest.register_entity(name, { use_texture_alpha = def.use_texture_alpha, + head_swivel = def.head_swivel or nil, + bone_eye_height = def.bone_eye_height or 1.4, stepheight = def.stepheight or 0.6, name = name, description = def.description, diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_villager.b3d index a941ca8efffe8ffdd3a7d389bd876e6e931f7450..97bca51a43595babb79ad7a451cae578055adb9f 100644 GIT binary patch delta 1584 zcmZ9LKWGzS7{+rkZ6dv*!D~%0)fAN$YpOBUs7KL-skz=J1%+pz}BqV zdLxm5_H(e@J7s+_Sc|_Jvi|yA@7e#>U7x%8{;^_aHGM|2SP~0`>+{j&TX$|RFS3up z@w!#*v$KaI4pvef(h+t}9h1gDkAnI@$3c&Q9tZVyW^epHk zXoxE-7#`ftN=ArfRF8BXCeF0NR#cZ1fpip91JyxepmERyS60ll8!7M%&@@bj&CV9d z1V0O!gXxyJ$TzX+EcDrGwwt~PiOT>+f9uc?KNp{4~_AjLXCn(_Ej~qZ!eAUo{Jhzo%CjP(%VO4 zyyv0DChhgdNbdlR@t&6&#TePQL3;;jjQ0*vV>nKFOL4MqgvNMplp0&uYa*zI!omrq z{cD&`h+|g~stDzj!Wx+CNs62wVHROKsj#)AIB&h{ib8*?(^Oa{C2|YsmJv1(DymEQ z`|SI3`|A(ulk`yr3~`c*u!O)Ldx~b?;N%CwP+GK;2tLy*YqV6s$vcEU2!}JGokv(f zc!KZ=K{7?yhj1C;9zqSFb?dBYIy!$&`2xMAiL5xPfKWnsiSQM{nG@kK!VQE+2%88E P1b1GvbOH5Z{+s(B#F<5% delta 536 zcmeynmSs&33!9UZv5N}ZL^gY-$E+LO_sBA-zSztvcU+RA%b0;7BQ-H)^14fUlP%>= zZq9q+$1%D5vdZKKZ#Xu~Up~P$dBbN3pn%BaJD(+3mhnnCO#bm%11KOd+2V@`L?Gac z282-qW32cBQX(?>$rp&8Nnas+o39YFGNAO7uTV2LKoz`!32=OanrQ-KBzyyzAv1Z& zHvx!kJHP@WlfQg}7^?6cM5|1W`OX1RkntUA#uOOi0F3eGJH$Z`ehM(UOfI-AJvrnD z)F}l&AW~~!0w;bzjrjs&DEx#diTMfFBQm+?rwG{3TYf^E^8iZo`~vX>CY$_{0n4X= z`6`na{Nk8=|AEEi2fq{`&Sm)xG1cL>#N_^mB9n7~^ll(M<2TfnEl>p?fD)k4mH7je ku=oSfS@H)Wu>dBq2P*LcDB=ECW3$EIqmr9Xm|vO&0M@MTTmS$7 diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index d623e7ca9..e7194330f 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1218,6 +1218,10 @@ mcl_mobs:register_mob("mobs_mc:villager", { "mobs_mc_villager.png", "mobs_mc_villager.png", --hat }, + --EXPERIMENTAL + head_swivel = "Head_Control", + bone_eye_height = 2.35, + ------------------------------- visual_size = {x=2.75, y=2.75}, makes_footstep_sound = true, walk_velocity = 1.2,