0
0
Fork 0

Make mobs flop when outside of flying node

This commit is contained in:
jordan4ibanez 2021-04-16 21:08:54 -04:00
parent 84ca7681fc
commit f1141aed9f
2 changed files with 62 additions and 14 deletions

View File

@ -193,41 +193,54 @@ local fly_state_switch = function(self, dtime)
self.state_timer = math.random(4,10) + math.random()
self.state = fly_state_list_wandering[math.random(1,#fly_state_list_wandering)]
end
end
--this is going to need some more logic gates because birds can flop around
local flop = function(self,dtime)
mobs.flop(self)
end
-- states are executed here
local fly_state_execution = function(self,dtime)
local pos = self.object:get_pos()
local current_node = minetest_get_node(pos).name
local inside_swim_node = false
local inside_fly_node = false
--quick scan everything to see if inside fly node
for _,id in pairs(self.fly_in) do
if id == current_node then
inside_swim_node = true
inside_fly_node = true
break
end
end
print(inside_swim_node)
if self.state == "stand" then
--do animation
--mobs.set_mob_animation(self, "stand")
--set the velocity of the mob
--mobs.set_velocity(self,0)
--print("standing")
elseif self.state == "fly" then
--print("flying")
--fly properly if inside fly node
if inside_fly_node then
if self.state == "stand" then
--do animation
--mobs.set_mob_animation(self, "stand")
--set the velocity of the mob
--mobs.set_velocity(self,0)
--print("standing")
elseif self.state == "fly" then
--print("flying")
end
--flop around if not inside fly node
else
--print("flopping")
flop(self,dtime)
end
end

View File

@ -1,10 +1,15 @@
local math_pi = math.pi
local math_sin = math.sin
local math_cos = math.cos
local math_random = math.random
local DOUBLE_PI = math_pi * 2
-- localize vector functions
local vector_new = vector.new
local vector_length = vector.length
local vector_new = vector.new
local vector_length = vector.length
local vector_multiply = vector.multiply
local minetest_yaw_to_dir = minetest.yaw_to_dir
-- move mob in facing direction
--this has been modified to be internal
@ -60,7 +65,37 @@ mobs.jump = function(self, velocity)
return
end
--fallback velocity to allow modularity
velocity = velocity or 8
self.object:add_velocity(vector_new(0,velocity,0))
end
--make mobs flop
mobs.flop = function(self, velocity)
if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then
return false
end
mobs.set_velocity(self, 0)
--fallback velocity to allow modularity
velocity = velocity or 8
--create a random direction (2d yaw)
local dir = DOUBLE_PI * math_random()
--create a random force value
local force = math_random(0,3) + math_random()
--convert the yaw to a direction vector then multiply it times the force
local final_additional_force = vector_multiply(minetest_yaw_to_dir(dir), force)
--place in the "flop" velocity to make the mob flop
final_additional_force.y = velocity
self.object:add_velocity(final_additional_force)
return true
end