Make Zombie model and head rotation work

This commit is contained in:
epCode 2022-06-07 13:59:08 -07:00
parent 36ddec9812
commit b991bb5291
4 changed files with 25 additions and 10 deletions

View File

@ -3656,26 +3656,33 @@ local mob_step = function(self, dtime)
local oldp,oldr = self.object:get_bone_position(self.head_swivel) local oldp,oldr = self.object:get_bone_position(self.head_swivel)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 10)) do for _, obj in pairs(minetest.get_objects_inside_radius(pos, 10)) do
if obj:is_player() then if obj:is_player() and not self.attack then
if not self._locked_object then if not self._locked_object then
if math.random(50) == 1 then if math.random(50/self.curiosity) == 1 then
self._locked_object = obj self._locked_object = obj
end end
else else
if math.random(200) == 1 then if math.random(200*self.curiosity) == 1 then
self._locked_object = nil self._locked_object = nil
end end
end end
end end
end end
if self.attack then
self._locked_object = self.attack
end
if self._locked_object then if self._locked_object then
local self_rot = self.object:get_rotation()
local player_pos = self._locked_object:get_pos() 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 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_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))--+self.head_yaw_offset
local mob_pitch = math.deg(-dir_to_pitch(direction_player)) local mob_pitch = math.deg(-dir_to_pitch(direction_player))
if mob_yaw < -60 or mob_yaw > 60 then if (mob_yaw < -60 or mob_yaw > 60) and not self.attack then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.multiply(oldr, 0.9)) self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.multiply(oldr, 0.9))
elseif self.attack then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,0), vector.new(mob_pitch, mob_yaw, 0))
else 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)) 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 end
@ -3926,8 +3933,10 @@ end
minetest.register_entity(name, { minetest.register_entity(name, {
use_texture_alpha = def.use_texture_alpha, use_texture_alpha = def.use_texture_alpha,
head_swivel = def.head_swivel or nil, head_swivel = def.head_swivel or nil, -- name of head bone
bone_eye_height = def.bone_eye_height or 1.4, head_yaw_offset = def.head_yaw_offset or 0, -- name of head bone
bone_eye_height = def.bone_eye_height or 1.4, -- mob eye height
curiosity = def.curiosity or 1, -- factor for staqring at players
stepheight = def.stepheight or 0.6, stepheight = def.stepheight or 0.6,
name = name, name = name,
description = def.description, description = def.description,

View File

@ -1221,6 +1221,7 @@ mcl_mobs:register_mob("mobs_mc:villager", {
--EXPERIMENTAL --EXPERIMENTAL
head_swivel = "Head_Control", head_swivel = "Head_Control",
bone_eye_height = 2.35, bone_eye_height = 2.35,
curiosity = 10,
------------------------------- -------------------------------
visual_size = {x=2.75, y=2.75}, visual_size = {x=2.75, y=2.75},
makes_footstep_sound = true, makes_footstep_sound = true,

View File

@ -60,11 +60,16 @@ local zombie = {
mesh = "mobs_mc_zombie.b3d", mesh = "mobs_mc_zombie.b3d",
textures = { textures = {
{ {
"mobs_mc_empty.png", -- armor "mobs_mc_zombie.png", -- skin
"mobs_mc_zombie.png", -- texture "mcl_armor_chestplate_diamond.png", -- armor
"mobs_mc_empty.png", -- wielded_item "mobs_mc_empty.png", -- wielded item
} }
}, },
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = .1,
-------------------------------
visual_size = {x=3, y=3}, visual_size = {x=3, y=3},
makes_footstep_sound = true, makes_footstep_sound = true,
sounds = { sounds = {