Spawner: Part 1: Add initial code to find doors front/behind position.

Detect first floor nodes.
This commit is contained in:
Hector Franqui
2017-05-05 18:34:16 -04:00
parent f4c374314a
commit 9b3d458872
3 changed files with 63 additions and 87 deletions

75
npc.lua
View File

@ -994,81 +994,6 @@ mobs:register_mob("advanced_npc:npc", {
end
end
end
-- if self.follow_path then
-- self.home_timer = (self.home_timer or 0) + dtime
-- if self.home_timer < 1 then return end -- every 1 second
-- self.home_timer = 0
-- -- if self.time_of_day > 0.2 and self.time_of_day < 0.8 then
-- -- return -- return if not night time
-- -- end
-- local h = self.destination
-- --local h = {x = 1, y = 8, z = 2} -- destination coords
-- local p = self.object:getpos() -- mob position
-- -- lets try find a path, first take care of positions
-- -- since pathfinder is very sensitive
-- local pheight = self.collisionbox[5] - self.collisionbox[2]
-- -- round position to center of node to avoid stuck in walls
-- -- also adjust height for player models!
-- p.x = math.floor(p.x + 0.5)
-- p.y = math.floor(p.y + 0.5) - pheight
-- p.z = math.floor(p.z + 0.5)
-- local ssight, sground = minetest.line_of_sight(p, {
-- x = p.x, y = p.y - 4, z = p.z}, 1)
-- -- determine node above ground
-- if not ssight then
-- p.y = sground.y + 1
-- end
-- h.x = math.floor(h.x + 0.5)
-- h.y = math.floor(h.y + 0.5)
-- h.z = math.floor(h.z + 0.5)
-- local x, y, z = p.x - h.x, p.y - h.y, p.z - h.z
-- local dist = math.floor(math.sqrt(x * x + y * y + z * z))
-- minetest.log("Self pos : "..minetest.pos_to_string(p))
-- minetest.log("Self dest: "..minetest.pos_to_string(h))
-- if dist <= 1 then
-- print ("--- home!")
-- self.homepath = nil
-- self.state = "stand"
-- return
-- end
-- if self.homepath == nil then
-- self.homepath = minetest.find_path(p, h, 50, 3, 6, "A*")
-- print ("--- finding route", self.homepath, dist)
-- end
-- if self.homepath then
-- print ("--- following path", dist, #self.homepath)
-- local np = self.homepath[1] ; if not np then return end
-- if math.abs(np.x - p.x) + math.abs(np.z - p.z) < 0.6 then
-- table.remove(self.homepath, 1) ; print ("-- removed entry")
-- end
-- np = {x = np.x, y = np.y, z = np.z}
-- local vec = {x = np.x - p.x, z = np.z - p.z}
-- local yaw = (math.atan(vec.z / vec.x) + math.pi / 2) - self.rotate
-- if np.x > p.x then yaw = yaw + math.pi end
-- self.object:setyaw(yaw)
-- set_velocity(self, self.walk_velocity)
-- end
-- end
return self.freeze
end