--a movement test to move the head
mob_register.move_head = function(self,pos2,dtime)
if self.head_bone then
- --print(self.head_bone)
- local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
- --[[ debug
- if rotation then
- --print("--------------------------------")
- --rotation.x = rotation.x + 1
- rotation.z = rotation.z + 1
- rotation.y = 0
-
- if rotation.x > 90 then
- rotation.x = -90
+ if self.head_coord == "horizontal" then
+ --print(self.head_bone)
+ local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
+ --[[ debug
+ if rotation then
+ --print("--------------------------------")
+ --rotation.x = rotation.x + 1
+ rotation.z = rotation.z + 1
+ rotation.y = 0
+
+ if rotation.x > 90 then
+ rotation.x = -90
+ end
+ if rotation.z > 90 then
+ rotation.z = -90
+ end
+
+ --print(rotation.x)
+ self.object:set_bone_position(self.head_bone, head_position, rotation)
end
- if rotation.z > 90 then
- rotation.z = -90
+ ]]--
+
+ --print(self.head_rotation.y)
+ --if passed a direction to look
+ local pos = self.object:get_pos()
+ local body_yaw = self.object:get_yaw()
+
+ if not body_yaw then
+ return
end
- --print(rotation.x)
- self.object:set_bone_position(self.head_bone, head_position, rotation)
- end
- ]]--
-
- --print(self.head_rotation.y)
- --if passed a direction to look
- local pos = self.object:get_pos()
- local body_yaw = self.object:get_yaw()
- if not body_yaw then
- return
- end
-
- local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
-
-
- local body_yaw = minetest.dir_to_yaw(dir)
-
- --pos is where the head actually is
- pos = vector.add(pos,dir)
- pos.y = pos.y + self.head_height_offset
-
- --use this to literally look around
- self.head_pos = pos
-
- if self.debug_head_pos == true then
- 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 = "dirt.png",
- })
- end
-
- --if the function was given a pos
- if pos2 then
- --compare the head yaw to the body
- local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
-
- local goal_yaw = body_yaw-head_yaw
-
- --if within range then do calculations
- if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
- ---begin pitch calculation
- --feed a 2D coordinate flipped into dir to yaw to calculate pitch
- head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
- head_rotation.z = degrees(-goal_yaw)
- self.object:set_bone_position(self.head_bone, head_position, head_rotation)
- return(true)
- --nothing to look at
- else--dofile(path.."movement.lua")
+ local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
+
+
+ local body_yaw = minetest.dir_to_yaw(dir)
+
+ --pos is where the head actually is
+ pos = vector.add(pos,dir)
+ pos.y = pos.y + self.head_height_offset
+
+ --use this to literally look around
+ self.head_pos = pos
+
+ if self.debug_head_pos == true then
+ 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 = "dirt.png",
+ })
+ end
+
+ --if the function was given a pos
+ if pos2 then
+ --compare the head yaw to the body
+
+ local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
+
+ local goal_yaw = body_yaw-head_yaw
+
+ print(goal_yaw)
+
+ --if within range then do calculations
+ if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
+ ---begin pitch calculation
+ --feed a 2D coordinate flipped into dir to yaw to calculate pitch
+ head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
+ head_rotation.z = degrees(-goal_yaw)
+ self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+ return(true)
+ --nothing to look at
+ else--dofile(path.."movement.lua")
+ self.return_head_to_origin(self,dtime)
+ return(false)
+ end
+
+ --if nothing to look at
+ else
self.return_head_to_origin(self,dtime)
return(false)
end
+ --[[
+ elseif self.head_coord == "vertical" then
+
+ --print(self.head_bone)
+ local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
+
+ -- debug
+ if head_rotation then
+ print("test")
+ --print("--------------------------------")
+ --head_rotation.x = head_rotation.x + 1
+ head_rotation.y = head_rotation.y + 1
+ head_rotation.z = 0
+
+ if head_rotation.x > 90 then
+ head_rotation.x = -90
+ end
+ if head_rotation.z > 90 then
+ head_rotation.z = -90
+ end
+ if head_rotation.y > 90 then
+ head_rotation.y = -90
+ end
+
+ --print(rotation.x)
+ self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+ end
+
+
+ --print(self.head_rotation.y)
+ --if passed a direction to look
+
+ local pos = self.object:get_pos()
+ local body_yaw = self.object:get_yaw()
+ if not body_yaw then
+ return
+ end
+
+ local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
+
+
+ local body_yaw = minetest.dir_to_yaw(dir)
+
+ --pos is where the head actually is
+ pos = vector.add(pos,dir)
+ pos.y = pos.y + self.head_height_offset
+
+ --use this to literally look around
+ self.head_pos = pos
+
+ if self.debug_head_pos == true then
+ 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 = "dirt.png",
+ })
+ end
- --if nothing to look at
- else
- self.return_head_to_origin(self,dtime)
- return(false)
+ --if the function was given a pos
+ if pos2 then
+ --compare the head yaw to the body
+ local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
+
+ local goal_yaw = body_yaw-head_yaw
+
+ if goal_yaw < -math.pi then
+ goal_yaw = goal_yaw + math.pi
+ elseif goal_yaw > math.pi then
+ goal_yaw = goal_yaw - math.pi
+ end
+
+ print("goal_yaw="..goal_yaw,"body_yaw="..body_yaw,"head_yaw="..head_yaw)
+
+ --if within range then do calculations
+ if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
+ ---begin pitch calculation
+ --feed a 2D coordinate flipped into dir to yaw to calculate pitch
+ head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
+ head_rotation.y = degrees(goal_yaw)
+ self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+ return(true)
+ --nothing to look at
+ else--dofile(path.."movement.lua")
+ self.return_head_to_origin(self,dtime)
+ return(false)
+ end
+
+ --if nothing to look at
+ else
+ self.return_head_to_origin(self,dtime)
+ return(false)
+ end
+ ]]--
end
end
end
--this sets the mob to move it's head back to pointing forwards
mob_register.return_head_to_origin = function(self,dtime)
- local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
- --make the head yaw move back
- if head_rotation.x > 0 then
- head_rotation.x = head_rotation.x - (dtime*100)
- elseif head_rotation.x < 0 then
- head_rotation.x = head_rotation.x + (dtime*100)
- end
-
- if math.abs(head_rotation.x) < (dtime*100) then
- head_rotation.x = 0
- end
-
+ local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
- --move up down (pitch) back to center
- if head_rotation.z > 0 then
- head_rotation.z = head_rotation.z - (dtime*100)
- elseif head_rotation.z < 0 then
- head_rotation.z = head_rotation.z + (dtime*100)
- end
-
- if math.abs(head_rotation.z) < (dtime*100) then
- head_rotation.z = 0
+ if self.head_coord == "horizontal" then
+ --make the head yaw move back
+ if head_rotation.x > 0 then
+ head_rotation.x = head_rotation.x - (dtime*100)
+ elseif head_rotation.x < 0 then
+ head_rotation.x = head_rotation.x + (dtime*100)
+ end
+
+ if math.abs(head_rotation.x) < (dtime*100) then
+ head_rotation.x = 0
+ end
+
+
+ --move up down (pitch) back to center
+ if head_rotation.z > 0 then
+ head_rotation.z = head_rotation.z - (dtime*100)
+ elseif head_rotation.z < 0 then
+ head_rotation.z = head_rotation.z + (dtime*100)
+ end
+
+ if math.abs(head_rotation.z) < (dtime*100) then
+ head_rotation.z = 0
+ end
+ elseif self.head_coord == "vertical" then
+ --make the head yaw move back
+ if head_rotation.x > 0 then
+ head_rotation.x = head_rotation.x - (dtime*100)
+ elseif head_rotation.x < 0 then
+ head_rotation.x = head_rotation.x + (dtime*100)
+ end
+
+ if math.abs(head_rotation.x) < (dtime*100) then
+ head_rotation.x = 0
+ end
+
+
+ --move up down (pitch) back to center
+ if head_rotation.y > 0 then
+ head_rotation.y = head_rotation.y - (dtime*100)
+ elseif head_rotation.y < 0 then
+ head_rotation.y = head_rotation.y + (dtime*100)
+ end
+
+ if math.abs(head_rotation.y) < (dtime*100) then
+ head_rotation.y = 0
+ end
end
-
self.object:set_bone_position(self.head_bone, head_position, head_rotation)
end
return(mob_register)
head_height_offset = 0.8, --added to the base y position
head_rotation_offset = math.pi,
--use this to correct the head position initially because it becomes severly offset - look at your blender model to get this perfect
- head_position_correction = vector.new(0,3,-0.5),
+ head_position_correction = vector.new(0,3,-0.5),
+ head_coord = "horizontal",
-----
is_visible = true,
}
)
-
+]]--
mobs.register_mob(
{
- mobname = "exploder",
+ mobname = "creeper",
physical = true,
collide_with_objects = false,
- collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
+ collisionbox = {-0.37,0, -0.37, 0.37, 0.5, 0.37},
visual = "mesh",
- visual_size = {x = 3, y = 3},
- mesh = "exploder.b3d",
+ visual_size = {x = 3.2, y = 3.2},
+ mesh = "creeper.b3d",
textures = {
- "creepig_body.png","creepig_leg.png","creepig_leg.png","creepig_leg.png","creepig_leg.png"
+ "creeper.png"
},
is_visible = true,
pointable = true,
- automatic_face_movement_dir = 0,
automatic_face_movement_max_rotation_per_sec = 300,
makes_footstep_sound = false,
hp = 10,
gravity = {x = 0, y = -9.81, z = 0},
movement_type = "walk",
- max_speed = 4,
+ max_speed = 0.1,
hostile = false,
state = 0,
view_distance = 20,
item_drop = "mob:cooked_porkchop",
- standing_frame = {x=5,y=5},
- moving_frame = {x=0,y=20},
- animation_multiplier = 10,
+ standing_frame = {x=0,y=0},
+ moving_frame = {x=0,y=40},
+ animation_multiplier = 20,
----
+
+
+ --these are used to anchor a point to the head position
+ -----
+ automatic_face_movement_dir = -90,
+ head_bone = "head",
+ debug_head_pos = true,
+ head_directional_offset = 2, --used in vector.multiply(minetest.yaw_to_dir(body_yaw),head_offset)
+ head_height_offset = 1.45, --added to the base y position
+ head_rotation_offset = 0,
+ --use this to correct the head position initially because it becomes severly offset - look at your blender model to get this perfect
+ head_position_correction = vector.new(0,2.4,0),
+ head_coord = "vertical",
+ -----
- has_head = false, --remove this when mesh based head rotation is implemented
- --head_visual = "mesh",
- --head_visual_size = {x = 1, y = 1},
- --head_mesh = "pig_head.x",
- --head_textures ={"creepig_head.png","creepig_nose.png"},
- --head_mount = vector.new(0,1.2,1.9),
death_rotation = "x",
--die_in_light_level = 12,
}
)
-]]--
+