#363 Turn on head logic

This commit is contained in:
kay27 2022-07-20 15:43:26 +03:00
parent 03e20912b4
commit 79cca6b121
5 changed files with 22 additions and 9 deletions

View File

@ -88,7 +88,7 @@ local function land_state_switch(self, dtime)
end
--ignore everything else if following
if mobs.check_following(self) and
if mobs.check_following(self, dtime) and
(not self.breed_lookout_timer or (self.breed_lookout_timer and self.breed_lookout_timer == 0)) and
(not self.breed_timer or (self.breed_timer and self.breed_timer == 0)) then
self.state = "follow"
@ -984,7 +984,7 @@ function mobs.mob_step(self, dtime)
--go get the closest player
if attacking then
mobs.do_head_logic(self, dtime, attacking)
self.memory = 6 --6 seconds of memory
--set initial punch timer
@ -1040,6 +1040,7 @@ function mobs.mob_step(self, dtime)
--don't break eye contact
if self.hostile and self.attacking then
mobs.set_yaw_while_attacking(self)
mobs.do_head_logic(self, dtime, self.attacking)
end
--perfectly reset pause_timer

View File

@ -3,7 +3,7 @@ local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius
local vector = vector
--check to see if someone nearby has some tasty food
mobs.check_following = function(self) -- returns true or false
mobs.check_following = function(self, dtime) -- returns true or false
--ignore
if not self.follow then
self.following_person = nil
@ -15,6 +15,7 @@ mobs.check_following = function(self) -- returns true or false
--check if the follower is a player incase they log out
if follower and follower:is_player() then
mobs.do_head_logic(self, dtime, follower)
local stack = follower:get_wielded_item()
--safety check
if not stack then

View File

@ -6,9 +6,9 @@ local degrees = function(yaw)
return yaw*180.0/math.pi
end
mobs.do_head_logic = function(self,dtime)
mobs.do_head_logic = function(self, dtime, player)
local player = minetest.get_player_by_name("singleplayer")
local player = player or minetest.get_player_by_name("singleplayer")
local look_at = player:get_pos()
look_at.y = look_at.y + player:get_properties().eye_height
@ -89,10 +89,21 @@ mobs.do_head_logic = function(self,dtime)
head_pitch = head_pitch + self.head_pitch_modifier
end
if self.swap_y_with_x then
self.object:set_bone_position(self.head_bone, bone_pos, vector.new(degrees(head_pitch),degrees(head_yaw),0))
local head_bone = self.head_bone
if (type(head_bone) == "table") then
for _, v in pairs(head_bone) do
if self.swap_y_with_x then
self.object:set_bone_position(v, bone_pos, vector.new(degrees(head_pitch),degrees(head_yaw),0))
else
self.object:set_bone_position(v, bone_pos, vector.new(degrees(head_pitch),0,degrees(head_yaw)))
end
end
else
self.object:set_bone_position(self.head_bone, bone_pos, vector.new(degrees(head_pitch),0,degrees(head_yaw)))
if self.swap_y_with_x then
self.object:set_bone_position(head_bone, bone_pos, vector.new(degrees(head_pitch),degrees(head_yaw),0))
else
self.object:set_bone_position(head_bone, bone_pos, vector.new(degrees(head_pitch),0,degrees(head_yaw)))
end
end
--set_bone_position([bone, position, rotation])
end

View File

@ -82,7 +82,7 @@ mobs:register_mob("mobs_mc:sheep", {
--head code
has_head = true,
head_bone = "head",
head_bone = {"hea1", "hea2",},
swap_y_with_x = false,
reverse_head_yaw = false,