master
runs 2020-05-28 22:52:39 +02:00
parent 035c02e4c0
commit 7acbedd965
14 changed files with 241 additions and 59 deletions

View File

@ -1,67 +1,56 @@
local modpath, S = ...
--make sure this is redefined as shown below aka
--don't run mob_rotation_degree_to_radians(rotation)
--run local radians = mob_rotation_degree_to_radians(rotation)
--or the mobs head rotation will become overwritten
local head_rotation_to_radians = function(rotation)
return{
x = 0, --roll should never be changed
y = degrees_to_radians(180 - rotation.y)*-1,
z = degrees_to_radians(90 - rotation.z)
}
function petz.bh_look_at(self, player_pos, prty)
if not(self.status == "looking") then
mobkit.animate(self, "idle")
petz.hq_look_at(self, player_pos, prty)
return true
end
end
function petz.hq_look_at(self, player_pos, prty)
local func = function(self)
if not(self.status == "looking") then
local random_time = math.random(2, 3)
petz.move_head(self, player_pos)
minetest.after(random_time, function(self)
if mobkit.is_alive(self) then
mobkit.clear_queue_low(self)
mobkit.clear_queue_high(self)
petz.return_head_to_origin(self)
self.looking = false
self.status = ""
return true
end
end, self)
self.status = "looking"
end
end
mobkit.queue_high(self, func, prty)
end
--a movement test to move the head
petz.move_head = function(self, tpos, dtime)
local head_position, head_rotation = self.object:get_bone_position("head")
local pos = self.object:get_pos()
head_position = self.head_position
local direction = vector.direction(pos, tpos)
--local yaw = minetest.dir_to_yaw(look_at_dir)
--local body_yaw = self.object:get_yaw()
look_at_dir = vector.normalize(direction)
local yaw = mokapi.yaw_to_degrees(math.asin(look_at_dir.y))
--local yaw =mokapi.yaw_to_degrees(math.atan2(look_at_dir.x, look_at_dir.z))
--yaw = mokapi.degrees(yaw)
minetest.chat_send_all("yaw= "..tostring(yaw))
--local pitch = mokapi.yaw_to_degrees(math.asin(look_at_dir.y))
--local roll = 0
--head_rotation.y = mokapi.yaw_to_degrees(yaw)
--head_rotation.x = mokapi.yaw_to_degrees(pitch)
--head_rotation.x = head_rotation. + yaw
if yaw < 60 and yaw > -60 then
head_rotation = {x= -90, y= 90-yaw, z= 0}
minetest.chat_send_all("yes")
else
head_rotation = self.head_rotation
function petz.move_head(self, tpos)
local head_position, head_rotation = self.object:get_bone_position("head") -- get the pos and rotation of the head bone. Currently causes a bug!
local pos = self.object:get_pos() --the pos of the mob
tpos.y = tpos.y + 1.625 -- the pos of the eyes of the player
if not(self.head_position) then
local head_position, head_rotation = self.object:get_bone_position("head")
self.head_position = vector.add(head_position, self.head.position_correction) --correction of the pos by cause of the bug, and save it
end
self.object:set_bone_position("head", head_position, head_rotation)
local direction = vector.direction(pos, tpos) -- vector direction from mob to player's eyes
local body_yaw = mokapi.yaw_to_degrees(self.object:get_yaw()) --yaw of the body in degrees
look_at_dir = vector.normalize(direction) -- important: normalize the vector
-- Functions to calculate the pitch & yaw (in degrees):
local pitch = mokapi.yaw_to_degrees(math.asin(look_at_dir.y))
local yaw =mokapi.yaw_to_degrees(math.atan2(look_at_dir.x, look_at_dir.z))
final_yaw = yaw + body_yaw --get the head yaw in reference with the body
head_rotation = {x= pitch, y= final_yaw, z= 0} -- the head movement {pitch, yaw, roll}
self.head_rotation = vector.add(head_rotation, self.head.rotation_origin) --the offset for the rotation, depends on the blender model
self.object:set_bone_position("head", self.head_position, self.head_rotation) --set the head movement
end
--void lookAt(Vec3 center)
-- Vec3 direction = (center - position).normalized;
-- pitch = asin(direction.y);
-- yaw = atan2(direction.x, direction.z);
--}
--this sets the mob to move it's head back to pointing forwards
petz.return_head_to_origin = function(self, dtime)
local head_position, head_rotation = self.object:get_bone_position("head")
--make the head yaw move back
if head_rotation.x > 0 then
head_rotation.x = head_rotation.x - 1
elseif head_rotation.x < 0 then
head_rotation.x = head_rotation.x + 1
end
--move up down (pitch) back to center
if head_rotation.z > 0 then
head_rotation.z = head_rotation.z - 1
elseif head_rotation.z < 0 then
head_rotation.z = head_rotation.z + 1
end
self.object:set_bone_position("head", head_position, head_rotation)
petz.return_head_to_origin = function(self)
self.object:set_bone_position("head", self.head_position, self.head.rotation_origin)
end

View File

@ -195,6 +195,17 @@ function petz.herbivore_brain(self)
petz.bh_sleep(self, 2)
end
--Look_at Behaviour
if prty < 1 then
if petz.settings.look_at and player and self.head and petz.is_standing(self) and not(self.status == "looking") then
if math.random(1, petz.settings.look_at_random) == 1 then
if petz.hq_look_at(self, player:get_pos(), 1) then
return
end
end
end
end
--Roam default
if mobkit.is_queue_empty_high(self) and self.status == "" then
if not(self.can_fly) then

View File

@ -20,4 +20,4 @@ assert(loadfile(modpath .. "/mobkit/br_monster.lua"))(modpath, S)
assert(loadfile(modpath .. "/mobkit/br_predator.lua"))(modpath, S)
assert(loadfile(modpath .. "/mobkit/br_semiaquatic.lua"))(modpath, S)
assert(loadfile(modpath .. "/mobkit/helper_functions.lua"))(modpath, S)
--assert(loadfile(modpath .. "/mobkit/bh_head.lua"))(modpath, S)
assert(loadfile(modpath .. "/mobkit/bh_head.lua"))(modpath, S)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,169 @@
mtllib petz_leopard.mtl
o converted_out
v 0.125 -0.5 0.25
v 0.125 -0.5 0.3125
v 0.125 -0.3125 0.3125
v 0.125 -0.3125 0.25
v 0.0625 -0.5 0.25
v 0.0625 -0.5 0.3125
v 0.0625 -0.3125 0.3125
v 0.0625 -0.3125 0.25
v 0.125 -0.5 -0.125
v 0.125 -0.5 -0.0625
v 0.125 -0.3125 -0.0625
v 0.125 -0.3125 -0.125
v 0.0625 -0.5 -0.125
v 0.0625 -0.5 -0.0625
v 0.0625 -0.3125 -0.0625
v 0.0625 -0.3125 -0.125
v -0 -0.5 -0.125
v -0 -0.5 -0.0625
v -0 -0.3125 -0.0625
v -0 -0.3125 -0.125
v -0.0625 -0.5 -0.125
v -0.0625 -0.5 -0.0625
v -0.0625 -0.3125 -0.0625
v -0.0625 -0.3125 -0.125
v -0 -0.5 0.25
v -0 -0.5 0.3125
v -0 -0.3125 0.3125
v -0 -0.3125 0.25
v -0.0625 -0.5 0.25
v -0.0625 -0.5 0.3125
v -0.0625 -0.3125 0.3125
v -0.0625 -0.3125 0.25
v 0.125 -0.3125 -0.1875
v 0.125 -0.3125 0.375
v 0.125 -0.0625 0.375
v 0.125 -0.0625 -0.1875
v -0.0625 -0.3125 -0.1875
v -0.0625 -0.3125 0.375
v -0.0625 -0.0625 0.375
v -0.0625 -0.0625 -0.1875
v 0.1875 -0.1875 -0.4375
v 0.1875 -0.1875 -0.1875
v 0.1875 -2.23517e-08 -0.1875
v 0.1875 -2.23517e-08 -0.4375
v -0.125 -0.1875 -0.4375
v -0.125 -0.1875 -0.1875
v -0.125 -2.23517e-08 -0.1875
v -0.125 -2.23517e-08 -0.4375
v 0.0625 -0.125 0.375
v 0.0625 -0.125 0.5625
v 0.0625 -0.0625 0.5625
v 0.0625 -0.0625 0.375
v -1.11759e-08 -0.125 0.375
v -1.11759e-08 -0.125 0.5625
v -1.11759e-08 -0.0625 0.5625
v -1.11759e-08 -0.0625 0.375
v 0.125 0 -0.3125
v 0.125 0 -0.25
v 0.125 0.0625 -0.25
v 0.125 0.0625 -0.3125
v 0.0625 0 -0.3125
v 0.0625 0 -0.25
v 0.0625 0.0625 -0.25
v 0.0625 0.0625 -0.3125
v 0.0625 -0.25 0.5625
v 0.0625 -0.25 0.625
v 0.0625 -0.0624999 0.625
v 0.0625 -0.0624999 0.5625
v 3.72529e-09 -0.25 0.5625
v 3.72529e-09 -0.25 0.625
v 3.72529e-09 -0.0624999 0.625
v 3.72529e-09 -0.0624999 0.5625
v -0 0 -0.3125
v -0 0 -0.25
v -0 0.0625 -0.25
v -0 0.0625 -0.3125
v -0.0625 0 -0.3125
v -0.0625 0 -0.25
v -0.0625 0.0625 -0.25
v -0.0625 0.0625 -0.3125
v 0.125 -0.125 -0.4375
v 0.125 -0.125 -0.5
v 0.125 -0.1875 -0.5
v 0.125 -0.1875 -0.4375
v -0.0625001 -0.125 -0.4375
v -0.0625001 -0.125 -0.5
v -0.0625001 -0.1875 -0.5
v -0.0625001 -0.1875 -0.4375
usemtl none
s off
g back_right_leg
f 1 2 3 4
f 5 6 7 8
f 1 4 8 5
f 2 3 7 6
f 1 2 6 5
f 4 3 7 8
g front_right_leg
f 9 10 11 12
f 13 14 15 16
f 9 12 16 13
f 10 11 15 14
f 9 10 14 13
f 12 11 15 16
g front_left_leg
f 17 18 19 20
f 21 22 23 24
f 17 20 24 21
f 18 19 23 22
f 17 18 22 21
f 20 19 23 24
g back_left_leg
f 25 26 27 28
f 29 30 31 32
f 25 28 32 29
f 26 27 31 30
f 25 26 30 29
f 28 27 31 32
g body
f 33 34 35 36
f 37 38 39 40
f 33 36 40 37
f 34 35 39 38
f 33 34 38 37
f 36 35 39 40
g head
f 41 42 43 44
f 45 46 47 48
f 41 44 48 45
f 42 43 47 46
f 41 42 46 45
f 44 43 47 48
g top_tail
f 49 50 51 52
f 53 54 55 56
f 49 52 56 53
f 50 51 55 54
f 49 50 54 53
f 52 51 55 56
g right_ear
f 57 58 59 60
f 61 62 63 64
f 57 60 64 61
f 58 59 63 62
f 57 58 62 61
f 60 59 63 64
g bottom_tail
f 65 66 67 68
f 69 70 71 72
f 65 68 72 69
f 66 67 71 70
f 65 66 70 69
f 68 67 71 72
g left_ear
f 73 74 75 76
f 77 78 79 80
f 73 76 80 77
f 74 75 79 78
f 73 74 78 77
f 76 75 79 80
g nodebox11
f 81 82 83 84
f 85 86 87 88
f 81 84 88 85
f 82 83 87 86
f 81 82 86 85
f 84 83 87 88

Binary file not shown.

Binary file not shown.

View File

@ -66,6 +66,12 @@ horseshoe_speedup = 0.2
##lashing
lashing_tame_count = 3
##look_at
look_at = true
#random probability of look_at
#i.e. 5 means probability each 5 s
look_at_random = 5
##Petz look at when they are fed, its owner...
look_at = true

View File

@ -44,9 +44,13 @@ minetest.register_entity("petz:"..pet_name, {
lung_capacity = 10, -- seconds
max_hp = 10,
makes_footstep_sound = false,
head = {
rotation_origin = vector.new(-90, 0, 0), --in degrees
position_correction = vector.new(0, 0.3, -0.3),
},
attack={range=0.5, damage_groups={fleshy=3}},
animation = {
idle = {range={x=12, y=13}, speed=0, loop=false},
walk={range={x=1, y=12}, speed=25, loop=true},
run={range={x=13, y=25}, speed=25, loop=true},
stand={

View File

@ -69,6 +69,9 @@ petz.settings.poop_rate = tonumber(settings:get("poop_rate", "200"))
petz.settings.poop_decay = tonumber(settings:get("poop_decay", "1200"))
--Smoke particles when die
petz.settings.death_effect = settings:get_bool("death_effect", true)
--Look_at
petz.settings.look_at = settings:get_bool("look_at", true)
petz.settings.look_at_random = tonumber(settings:get("look_at_random", "10"))
--Cobweb
petz.settings.cobweb_decay = tonumber(settings:get("cobweb_decay", "1200"))
--Mount Pointable Driver