From 5a2773ea1abb6c8706c477802aae2fa60704714c Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sun, 25 Apr 2021 17:48:41 -0400 Subject: [PATCH] Add in basics of head code yaw --- .../mcl_mobs/api/mob_functions/ai.lua | 8 +- .../mcl_mobs/api/mob_functions/head_logic.lua | 86 ++++++++++++++++++- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index bb54f5b95..5ecb7c4fb 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -833,13 +833,13 @@ mobs.mob_step = function(self, dtime) --DEBUG TIME! - --mobs.do_head_logic(self,dtime) + mobs.do_head_logic(self,dtime) - --if true then--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG - -- return - --end + if true then--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG + return + end --despawn mechanism --don't despawned tamed or bred mobs 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 a294f5528..f4fc5e56d 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua @@ -1,12 +1,67 @@ local vector_new = vector.new + +--converts yaw to degrees +local degrees = function(yaw) + return(yaw*180.0/math.pi) +end + + mobs.do_head_logic = function(self,dtime) - --local yaw = self.object:get_yaw() + local player = minetest.get_player_by_name("singleplayer") + + local look_at = player:get_pos() + look_at.y = look_at.y + player:get_properties().eye_height - --local bone_pos = vector_new(0,5,0) + + local pos = self.object:get_pos() + + local body_yaw = self.object:get_yaw() + + local body_dir = minetest.yaw_to_dir(body_yaw) + + + --needs to be INTERNAL(API) + self.head_height_offset = 1.0525 + + pos.y = pos.y + self.head_height_offset + + --needs to be INTERNAL (API) + self.head_direction_offset = 0.5 + + local head_offset = vector.multiply(body_dir, self.head_direction_offset) + + pos = vector.add(pos, head_offset) + + + + + minetest.add_particle({ + pos = pos, + velocity = {x=0, y=0, z=0}, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.2, + size = 1, + texture = "default_dirt.png", + }) + + + local bone_pos = vector_new(0,0,0) + + + --needs to be INTERNAL (API) + --(horizontal) + self.head_bone_pos_y = 3.6 + bone_pos.y = self.head_bone_pos_y + + + --needs to be INTERNAL (API) + --(vertical) + self.head_bone_pos_z = -0.6 + bone_pos.z = self.head_bone_pos_z --print(yaw) @@ -15,7 +70,32 @@ mobs.do_head_logic = function(self,dtime) --bone_rot.x = bone_rot.x + (dtime * 10) --bone_rot.z = bone_rot.z + (dtime * 10) - --self.object:set_bone_position("head", bone_pos, bone_rot) + local head_yaw + + head_yaw = minetest.dir_to_yaw(vector.direction(pos,look_at)) - body_yaw + + + --over rotation protection + --stops radians from going out of spec + if head_yaw > math.pi then + head_yaw = head_yaw - (math.pi * 2) + elseif head_yaw < -math.pi then + head_yaw = head_yaw + (math.pi * 2) + end + + + --upper check + if head_yaw > math.pi - (math.pi/2) then + head_yaw = 0 + --lower check + elseif head_yaw < -math.pi + (math.pi/2) then + head_yaw = 0 + end + + + + + self.object:set_bone_position("head", bone_pos, vector_new(0,0,degrees(head_yaw)))