From d28e81bc9fc1f11b10da524d6874e8e1ee4a956d Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sun, 25 Apr 2021 17:54:14 -0400 Subject: [PATCH] Add in mobs look pitch --- .../mcl_mobs/api/mob_functions/head_logic.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua index f4fc5e56dd..612ef1d985 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua @@ -84,18 +84,28 @@ mobs.do_head_logic = function(self,dtime) end - --upper check + local check_failed = false + --upper check + 90 degrees or upper math.radians (3.14/2) if head_yaw > math.pi - (math.pi/2) then head_yaw = 0 - --lower check + check_failed = true + --lower check - 90 degrees or lower negative math.radians (-3.14/2) elseif head_yaw < -math.pi + (math.pi/2) then head_yaw = 0 + check_failed = true end - + local head_pitch = 0 + --DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG + --head_yaw = 0 + --DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG - self.object:set_bone_position("head", bone_pos, vector_new(0,0,degrees(head_yaw))) + if not check_failed then + head_pitch = minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(look_at.x,0,look_at.z)),0,pos.y-look_at.y))+(math.pi/2) + end + + self.object:set_bone_position("head", bone_pos, vector_new(degrees(head_pitch),0,degrees(head_yaw)))