Add dynamic altitdue adjustment during flight.

Still todo: stop flyers reliably from randomling "standing" in the
air.

Also contains a little testing easter mob-egg hehe.
This commit is contained in:
cora 2022-05-23 23:39:59 +02:00
parent ff6af32ddf
commit d1a37f38b4
10 changed files with 126 additions and 2 deletions

View File

@ -2487,7 +2487,9 @@ local do_states = function(self, dtime)
end
if self.facing_fence == true
or cliff_or_danger
or random(1, 100) <= 30 then
or random(1, 100) <= 30
or ( (self.fly and not self.keep_flying)
or not self.fly ) then
set_velocity(self, 0)
self.state = "stand"
@ -3559,6 +3561,9 @@ local mob_activate = function(self, staticdata, def, dtime)
-- run on_spawn function if found
if self.on_spawn and not self.on_spawn_run then
if self.fly then
self.desired_altitude = self.desired_altitude + math.random(-5,10)
end
if self.on_spawn(self) then
self.on_spawn_run = true -- if true, set flag to run once only
end
@ -3570,10 +3575,62 @@ local mob_activate = function(self, staticdata, def, dtime)
end
end
local function get_speed_over_ground(self)
local p = self.object:get_velocity()
return vector.length(vector.new(p.x,0,p.z))
end
local function check_ground(self) --return true if too close to the ground
local p = self.object:get_pos()
local n = minetest.find_nodes_in_area_under_air(vector.offset(p,0,-self.desired_altitude-1,0),vector.offset(p,0,0,0),{"group:solid"})
if #n > 0 then
return true
end
end
local function descend(self)
local v = self.object:get_velocity()
local gs = get_speed_over_ground(self)
local r = math.max(math.abs(self.fall_speed) - gs,1)
--minetest.log("descend "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r))
if v.y > self.fall_speed then
self.object:set_velocity(vector.new(v.x,-r,v.z))
end
end
local function climb(self)
local v = self.object:get_velocity()
local gs = get_speed_over_ground(self)
local r = self.run_velocity + gs
--minetest.log("climb "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r))
if v.y < self.walk_velocity then
self.object:add_velocity(vector.new(0,r/10,0))
end
end
--self.floater
--self.desired altitude (above ground)
local function check_flight(self,dtime)
if self.floater or not self.fly then return end --floaters don't need altitdude adjustment
--self.state = "walk"
if not self.flap_timer and check_ground(self) then
climb(self)
self.flap_timer = 0
elseif self.flap_timer then
if self.flap_timer > self.flap_time then
self.flap_timer = nil
else
self.flap_timer = self.flap_timer + dtime
end
else
descend(self)
end
end
-- main mob function
local mob_step = function(self, dtime)
check_item_pickup(self)
check_flight(self,dtime)
if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self)
end
@ -3904,7 +3961,7 @@ minetest.register_entity(name, {
xp_max = def.xp_max or 0,
xp_timestamp = 0,
breath_max = def.breath_max or 15,
breathes_in_water = def.breathes_in_water or false,
breathes_in_water = def.breathes_in_water or false,
physical = true,
collisionbox = collisionbox,
selectionbox = def.selectionbox or def.collisionbox,
@ -3915,6 +3972,9 @@ minetest.register_entity(name, {
view_range = def.view_range or 16,
walk_velocity = def.walk_velocity or 1,
run_velocity = def.run_velocity or 2,
desired_altitude = def.desired_altitude or 12, --over ground
flap_time = def.flap_time or 2, --time between wing glap / climb events
keep_flying = def.keep_flying or false,
damage = scale_difficulty(def.damage, 0, 0),
light_damage = def.light_damage or 0,
sunlight_damage = def.sunlight_damage or 0,

View File

@ -142,3 +142,5 @@ dofile(path .. "/slime+magma_cube.lua") -- Wuzzy
dofile(path .. "/spider.lua") -- Spider by AspireMint (fishyWET (CC-BY-SA 3.0 license for texture)
dofile(path .. "/vex.lua") -- KrupnoPavel
dofile(path .. "/wither.lua") -- Mesh and animation by toby109tt / https://github.com/22i
dofile(path .. "/phantom.lua") -- Mesh and animation by toby109tt / https://github.com/22i

Binary file not shown.

View File

@ -0,0 +1,62 @@
--Phantom for mcl2
--cora
--License for code WTFPL, cc0
local S = minetest.get_translator("mobs_mc")
mcl_mobs:register_mob("mobs_mc:phantom", {
description = S("Phantom"),
type = "monster",
spawn_class = "passive",
pathfinding = 1,
hp_min = 6,
hp_max = 6,
xp_min = 1,
xp_max = 3,
collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.89, 0.25},
visual = "mesh",
mesh = "mobs_mc_phantom.b3d",
textures = {{"mobs_mc_phantom.png","mobs_mc_phantom_e.png","mobs_mc_phantom_e_s.png"}},
visual_size = {x=3, y=3},
walk_velocity = 3,
run_velocity = 5,
desired_altitude = 19,
keep_flying = true,
sounds = {
random = "mobs_mc_phantom_random",
damage = {name="mobs_mc_phantom_hurt", gain=0.3},
death = {name="mobs_mc_phantom_death", gain=0.6},
eat = "mobs_mc_animal_eat_generic",
distance = 16,
},
drops = {
{name = "mcl_mobitems:leather", --TODO: phantom membrane
chance = 1,
min = 1,
max = 2,
looting = "common",},
},
animation = {
stand_speed = 50,
walk_speed = 50,
fly_speed = 50,
stand_start = 0,
stand_end = 0,
fly_start = 0,
fly_end = 30,
walk_start = 0,
walk_end = 30,
},
fall_damage = 0,
fall_speed = -2.25,
attack_type = "dogfight",
floats = 1,
physical = true,
fly = true,
makes_footstep_sound = false,
fear_height = 0,
view_range = 16,
})
-- spawn eggs
mcl_mobs:register_egg("mobs_mc:phantom", S("Phantom"), "mobs_mc_spawn_icon_phantom.png", 0)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B