add 'keep_flying' flag and random vertical flight changes
This commit is contained in:
parent
064b59f01d
commit
8b25ab4988
18
api.lua
18
api.lua
@ -508,9 +508,9 @@ function mobs:line_of_sight(entity, pos1, pos2, stepsize)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mob_class:attempt_flight_correction()
|
function mob_class:attempt_flight_correction(override)
|
||||||
|
|
||||||
if self:flight_check() then return true end
|
if self:flight_check() and override ~= true then return true end
|
||||||
|
|
||||||
-- We are not flying in what we are supposed to.
|
-- We are not flying in what we are supposed to.
|
||||||
-- See if we can find intended flight medium and return to it
|
-- See if we can find intended flight medium and return to it
|
||||||
@ -534,7 +534,7 @@ function mob_class:attempt_flight_correction()
|
|||||||
local escape_direction = vector.direction(pos, escape_target)
|
local escape_direction = vector.direction(pos, escape_target)
|
||||||
|
|
||||||
self.object:set_velocity(
|
self.object:set_velocity(
|
||||||
vector.multiply(escape_direction, self.run_velocity))
|
vector.multiply(escape_direction, 1)) --self.run_velocity))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -2191,6 +2191,12 @@ function mob_class:do_states(dtime)
|
|||||||
yaw = yaw + random(-0.5, 0.5)
|
yaw = yaw + random(-0.5, 0.5)
|
||||||
|
|
||||||
yaw = self:set_yaw(yaw, 8)
|
yaw = self:set_yaw(yaw, 8)
|
||||||
|
|
||||||
|
-- for flying/swimming mobs randomly move up and down also
|
||||||
|
if self.fly_in
|
||||||
|
and not self.following then
|
||||||
|
self:attempt_flight_correction(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- stand for great fall in front
|
-- stand for great fall in front
|
||||||
@ -2198,9 +2204,14 @@ function mob_class:do_states(dtime)
|
|||||||
or self.at_cliff
|
or self.at_cliff
|
||||||
or random(1, 100) <= self.stand_chance then
|
or random(1, 100) <= self.stand_chance then
|
||||||
|
|
||||||
|
-- don't stand if mob flies and keep_flying set
|
||||||
|
if (self.fly and not self.keep_flying)
|
||||||
|
or not self.fly then
|
||||||
|
|
||||||
self:set_velocity(0)
|
self:set_velocity(0)
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
self:set_animation("stand", true)
|
self:set_animation("stand", true)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self:set_velocity(self.walk_velocity)
|
self:set_velocity(self.walk_velocity)
|
||||||
|
|
||||||
@ -3385,6 +3396,7 @@ minetest.register_entity(name, setmetatable({
|
|||||||
attack_type = def.attack_type,
|
attack_type = def.attack_type,
|
||||||
fly = def.fly,
|
fly = def.fly,
|
||||||
fly_in = def.fly_in,
|
fly_in = def.fly_in,
|
||||||
|
keep_flying = def.keep_flying,
|
||||||
owner = def.owner,
|
owner = def.owner,
|
||||||
order = def.order,
|
order = def.order,
|
||||||
on_die = def.on_die,
|
on_die = def.on_die,
|
||||||
|
1
api.txt
1
api.txt
@ -45,6 +45,7 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
'fly' when true allows your mob to fly around instead of walking.
|
'fly' when true allows your mob to fly around instead of walking.
|
||||||
'fly_in' holds the node name that the mob flies (or swims) around
|
'fly_in' holds the node name that the mob flies (or swims) around
|
||||||
in e.g. "air" or "default:water_source".
|
in e.g. "air" or "default:water_source".
|
||||||
|
'keep_flying' when true mobs like birds no longer stop and stand.
|
||||||
'stay_near' when set allows mobs the chance to stay around certain nodes.
|
'stay_near' when set allows mobs the chance to stay around certain nodes.
|
||||||
'nodes' string or table of nodes to stay nearby e.g. "farming:straw"
|
'nodes' string or table of nodes to stay nearby e.g. "farming:straw"
|
||||||
'chance' chance of searching for above node(s), default is 10.
|
'chance' chance of searching for above node(s), default is 10.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user