Add in basics of head code yaw

This commit is contained in:
jordan4ibanez 2021-04-25 17:48:41 -04:00
parent 555935ff3d
commit 5a2773ea1a
2 changed files with 87 additions and 7 deletions

View file

@ -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

View file

@ -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)))