1 --converts yaw to degrees
2 local degrees = function(yaw)
4 return(yaw*180.0/math.pi)
7 local degree_round = function(degree)
8 return(degree + 0.5 - (degree + 0.5) % 1)
11 local radians_to_degrees = function(radians)
12 return(radians*180.0/math.pi)
15 --a movement test to move the head
16 mob.move_head = function(self)
18 local pos = self.object:get_pos()
19 local body_yaw = self.object:get_yaw() - (math.pi/2)
20 local dir = vector.multiply(minetest.yaw_to_dir(body_yaw),0.72)
21 local real_dir = minetest.yaw_to_dir(body_yaw)
22 local body_yaw = degree_round(degrees(minetest.dir_to_yaw(dir)))
24 pos = vector.add(pos,dir)
27 --pos is where the head actually is
29 for _,object in ipairs(minetest.get_objects_inside_radius(pos, 6)) do
30 if object:is_player() then
31 local pos2 = object:get_pos()
32 pos2.y = pos2.y + 1.625
34 local head_yaw = degree_round(degrees(minetest.dir_to_yaw(vector.direction(pos,pos2))))
36 local new_yaw = (head_yaw-body_yaw)
40 if math.abs(new_yaw) <= 90 or math.abs(new_yaw) >= 270 then
41 --do other calculations on pitch and roll
43 local triangle = vector.new(vector.distance(pos,pos2),0,pos2.y-pos.y)
45 local tri_yaw = minetest.dir_to_yaw(triangle)+(math.pi/2)
47 pitch = radians_to_degrees(tri_yaw)
49 local pitch_adjustment = 0
51 if new_yaw >= 270 then
52 pitch_adjustment = new_yaw - 180
53 elseif new_yaw <= -270 then
54 pitch_adjustment = new_yaw + 180
56 pitch_adjustment = new_yaw
59 local roll_adjustment = pitch_adjustment
61 pitch_adjustment = 1-(math.abs(pitch_adjustment)/90)
62 pitch = pitch-- * pitch_adjustment
65 --------------------------------
67 local roll_adjustment = 1-pitch_adjustment
70 local side_adjuster = 1
75 roll = (radians_to_degrees(tri_yaw)*side_adjuster)*roll_adjustment
85 self.child:set_attach(self.object, "", vector.new(2.4,1.2,0), vector.new(180+roll, new_yaw, 180+pitch))
86 --self.head_rotation = vector.new(180,new_yaw,180)