reasonably working basic step function
This commit is contained in:
parent
7e50b30d80
commit
eb8bbfab12
58
api_fast.lua
58
api_fast.lua
@ -14,6 +14,7 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
rotate = 0,
|
rotate = 0,
|
||||||
physical = true,
|
physical = true,
|
||||||
weight = 5,
|
weight = 5,
|
||||||
|
jump_height = 6,
|
||||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
visual_size = {x=1, y=1},
|
visual_size = {x=1, y=1},
|
||||||
@ -31,6 +32,8 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
bt = nil,
|
bt = nil,
|
||||||
btData = nil,
|
btData = nil,
|
||||||
|
|
||||||
|
jump_timer = 0,
|
||||||
|
walk_timer = 0,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local btdata = self.btData
|
local btdata = self.btData
|
||||||
@ -64,7 +67,6 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
self.bt_timer = 0
|
self.bt_timer = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
btdata.lastpos = pos
|
|
||||||
|
|
||||||
|
|
||||||
-- handle movement
|
-- handle movement
|
||||||
@ -85,11 +87,16 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
|
|
||||||
-- TODO: fall damage
|
-- TODO: fall damage
|
||||||
|
|
||||||
|
self.jump_timer = self.jump_timer + dtime
|
||||||
|
|
||||||
|
|
||||||
if self.destination ~= nil then
|
if self.destination ~= nil then
|
||||||
|
|
||||||
|
self.walk_timer = self.walk_timer + dtime
|
||||||
|
|
||||||
--print("destination ")
|
--print("destination ")
|
||||||
|
|
||||||
|
local tdist = distance(pos, btdata.lastpos)
|
||||||
local dist = distance(pos, self.destination)
|
local dist = distance(pos, self.destination)
|
||||||
-- print("walk dist ".. dist)
|
-- print("walk dist ".. dist)
|
||||||
local s = self.destination
|
local s = self.destination
|
||||||
@ -99,43 +106,45 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
z = pos.z - s.z
|
z = pos.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
if vec.x ~= 0 or vec.z ~= 0 then
|
if tdist < self.walk_velocity * dtime * .9 and self.walk_timer > 1 then
|
||||||
|
|
||||||
yaw = (math.atan(vec.z / vec.x) + math.pi / 2) - self.rotate
|
if self.jump_timer > 4 then
|
||||||
|
local v = self.object:getvelocity()
|
||||||
|
|
||||||
if s.x > pos.x then
|
v.y = self.jump_height + 1
|
||||||
yaw = yaw + math.pi
|
v.x = v.x * 2.2
|
||||||
|
v.z = v.z * 2.2
|
||||||
|
|
||||||
|
self.object:setvelocity(v)
|
||||||
|
|
||||||
|
self.jump_timer = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print("yaw " .. yaw)
|
|
||||||
|
|
||||||
|
yaw = (math.atan2(vec.z, vec.x) + math.pi / 2) - self.rotate
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
end
|
|
||||||
|
|
||||||
if dist > (self.approachDistance or .1) then
|
if dist > (self.approachDistance or .1) then
|
||||||
--[[
|
|
||||||
if (self.jump
|
|
||||||
and get_velocity(self) <= 0.5
|
|
||||||
and self.object:getvelocity().y == 0)
|
|
||||||
or (self.object:getvelocity().y == 0
|
|
||||||
and self.jump_chance > 0) then
|
|
||||||
do_jump(self)
|
|
||||||
end]]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set_velocity(self, self.walk_velocity)
|
set_velocity(self, self.walk_velocity)
|
||||||
set_animation(self, "walk")
|
set_animation(self, "walk")
|
||||||
else
|
else
|
||||||
-- we have arrived
|
-- we have arrived
|
||||||
self.destination = nil
|
self.destination = nil
|
||||||
|
self.walk_timer = 0
|
||||||
|
|
||||||
-- TODO: bump bttimer to get new directions
|
-- bump bttimer to get new directions
|
||||||
|
self.bt_timer = 99
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
set_animation(self, "stand")
|
set_animation(self, "stand")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
btdata.lastpos = pos
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
@ -282,11 +291,6 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
self.btData.mob = nil -- just in case
|
self.btData.mob = nil -- just in case
|
||||||
end
|
end
|
||||||
|
|
||||||
-- used to rotate older mobs
|
|
||||||
if self.drawtype
|
|
||||||
and self.drawtype == "side" then
|
|
||||||
self.rotate = math.rad(90)
|
|
||||||
end
|
|
||||||
|
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
|
|
||||||
@ -305,19 +309,15 @@ function mobehavior:register_mob_fast(name, def)
|
|||||||
return minetest.serialize(tmp)
|
return minetest.serialize(tmp)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for k,v in pairs(def) do
|
for k,v in pairs(def) do
|
||||||
mdef[k] = v
|
mdef[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_entity(name, mdef)
|
minetest.register_entity(name, mdef)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
12
entities.lua
12
entities.lua
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
function make_bunny(name, behavior_fn)
|
function make_bunny(name, behavior_fn)
|
||||||
|
|
||||||
mobs:register_simple_mob(mn..":"..name, {
|
mobehavior:register_mob_fast(mn..":"..name, {
|
||||||
type = "animal",
|
type = "animal",
|
||||||
passive = true,
|
passive = true,
|
||||||
reach = 1,
|
reach = 1,
|
||||||
@ -62,7 +62,7 @@ end
|
|||||||
|
|
||||||
function make_wolf(name, behavior_fn)
|
function make_wolf(name, behavior_fn)
|
||||||
|
|
||||||
mobs:register_simple_mob(mn..":"..name, {
|
mobehavior:register_mob_fast(mn..":"..name, {
|
||||||
|
|
||||||
type = "animal",
|
type = "animal",
|
||||||
passive = false,
|
passive = false,
|
||||||
@ -74,7 +74,7 @@ function make_wolf(name, behavior_fn)
|
|||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "animal_wolf.b3d",
|
mesh = "animal_wolf.b3d",
|
||||||
drawtype = "front",
|
drawtype = "front",
|
||||||
rotate = 270,
|
rotate = math.pi / -2,
|
||||||
textures = {
|
textures = {
|
||||||
{"animal_wolf_mesh.png"},
|
{"animal_wolf_mesh.png"},
|
||||||
{"animal_wolf_tamed_mesh.png"},
|
{"animal_wolf_tamed_mesh.png"},
|
||||||
@ -124,7 +124,7 @@ end
|
|||||||
|
|
||||||
function make_bear(name, behavior_fn)
|
function make_bear(name, behavior_fn)
|
||||||
|
|
||||||
mobs:register_simple_mob(mn..":"..name, {
|
mobehavior:register_mob_fast(mn..":"..name, {
|
||||||
|
|
||||||
type = "animal",
|
type = "animal",
|
||||||
passive = false,
|
passive = false,
|
||||||
@ -137,7 +137,7 @@ function make_bear(name, behavior_fn)
|
|||||||
mesh = "mob_bear.b3d",
|
mesh = "mob_bear.b3d",
|
||||||
drawtype = "front",
|
drawtype = "front",
|
||||||
visual_size= {x=3,y=3,z=3},
|
visual_size= {x=3,y=3,z=3},
|
||||||
rotate = 270,
|
rotate = math.pi / -2,
|
||||||
textures = {
|
textures = {
|
||||||
{"mob_bear_bear_mesh.png"},
|
{"mob_bear_bear_mesh.png"},
|
||||||
-- {"mob_bear_bear_tamed_mesh.png"}, -- has a harness
|
-- {"mob_bear_bear_tamed_mesh.png"}, -- has a harness
|
||||||
@ -187,7 +187,7 @@ end
|
|||||||
|
|
||||||
function make_rat(name, behavior_fn)
|
function make_rat(name, behavior_fn)
|
||||||
|
|
||||||
mobs:register_simple_mob(mn..":"..name, {
|
mobehavior:register_mob_fast(mn..":"..name, {
|
||||||
type = "animal",
|
type = "animal",
|
||||||
passive = true,
|
passive = true,
|
||||||
reach = 1,
|
reach = 1,
|
||||||
|
60
giant.lua
60
giant.lua
@ -112,6 +112,59 @@ local lumberjack = function()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local bare_lumberjack = function()
|
||||||
|
return bt.Sequence("", {
|
||||||
|
|
||||||
|
-- build a chest and remember where it is
|
||||||
|
bt.FindSpotOnGround(),
|
||||||
|
bt.Approach(2),
|
||||||
|
bt.SetNode({name="default:chest"}),
|
||||||
|
-- bt.GetGroupWaypoint("lumber_chest"),
|
||||||
|
bt.SetWaypoint("chest"),
|
||||||
|
|
||||||
|
bt.UntilFailed(bt.Sequence("logs some trees", {
|
||||||
|
|
||||||
|
-- find a tree
|
||||||
|
bt.Selector("find a tree", {
|
||||||
|
bt.Sequence("find a tree near the last one", {
|
||||||
|
bt.GetWaypoint("tree"),
|
||||||
|
bt.FindNodeNear({"group:tree"}, 15),
|
||||||
|
}),
|
||||||
|
bt.FindNodeNear({"group:tree"}, 50),
|
||||||
|
}),
|
||||||
|
bt.Approach(2),
|
||||||
|
|
||||||
|
-- chop it down
|
||||||
|
bt.Invert(bt.UntilFailed(bt.Sequence("chop tree", {
|
||||||
|
bt.Wield("default:axe_steel"),
|
||||||
|
bt.Animate("punch"),
|
||||||
|
bt.FindNodeNear({"group:tree"}, 3), -- gets stuck on aspen and jungle
|
||||||
|
bt.DigNode(),
|
||||||
|
bt.WaitTicks(1),
|
||||||
|
}))),
|
||||||
|
bt.SetWaypointHere("tree"),
|
||||||
|
|
||||||
|
bt.Wield(""),
|
||||||
|
|
||||||
|
|
||||||
|
bt.Succeed(bt.Sequence("pick up saplings", {
|
||||||
|
--bt.FindItemNear("group:sapling", 20),
|
||||||
|
bt.PickUpNearbyItems("group:sapling", 5),
|
||||||
|
})),
|
||||||
|
|
||||||
|
|
||||||
|
-- put wood in chest
|
||||||
|
bt.GetWaypoint("chest"),
|
||||||
|
bt.Approach(2),
|
||||||
|
bt.PutInChest(nil),
|
||||||
|
|
||||||
|
|
||||||
|
bt.WaitTicks(1),
|
||||||
|
--bt.Print("end of loop \n"),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local fence_region = function(item)
|
local fence_region = function(item)
|
||||||
return bt.Sequence("", {
|
return bt.Sequence("", {
|
||||||
|
|
||||||
@ -483,7 +536,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
|
||||||
make_wolf("wolf", function()
|
make_wolf("wolf", function()
|
||||||
return wander_around(6)
|
return wander_around(6)
|
||||||
end)
|
end)
|
||||||
@ -498,9 +551,10 @@ end)
|
|||||||
make_bear("bear", function()
|
make_bear("bear", function()
|
||||||
return wander_around(6)
|
return wander_around(6)
|
||||||
end)
|
end)
|
||||||
]]
|
|
||||||
|
|
||||||
make_NPC("npc", function()
|
make_NPC("npc", function()
|
||||||
return wander_around(6)
|
-- return wander_around(6)
|
||||||
|
return bare_lumberjack()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ minetest.register_abm({
|
|||||||
|
|
||||||
-- only if light levels are within range
|
-- only if light levels are within range
|
||||||
if lig and lig >= mlig and lig <= xlig then
|
if lig and lig >= mlig and lig <= xlig then
|
||||||
minetest.add_entity(pos2, mob)
|
-- minetest.add_entity(pos2, mob)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ minetest.register_abm({
|
|||||||
--print("----------spawning rat")
|
--print("----------spawning rat")
|
||||||
local p = minetest.find_node_near(pos, 3, "air")
|
local p = minetest.find_node_near(pos, 3, "air")
|
||||||
if p then
|
if p then
|
||||||
local mob = minetest.add_entity(p, "mobehavior:rat")
|
-- local mob = minetest.add_entity(p, "mobehavior:rat")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -108,7 +108,7 @@ minetest.register_abm({
|
|||||||
--print("----------spawning rat")
|
--print("----------spawning rat")
|
||||||
local p = minetest.find_node_near(pos, 3, "air")
|
local p = minetest.find_node_near(pos, 3, "air")
|
||||||
if p then
|
if p then
|
||||||
local mob = minetest.add_entity(p, "mobehavior:bunny")
|
-- local mob = minetest.add_entity(p, "mobehavior:bunny")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user