1
0
Fork 0

Make underwater mobs try to continuously swim around with quick_rotate_45

This commit is contained in:
jordan4ibanez 2021-04-17 12:36:19 -04:00
parent 061602d9d4
commit e8148f81ab
1 changed files with 37 additions and 20 deletions

View File

@ -13,6 +13,15 @@ local DOUBLE_PI = math.pi * 2
local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125 local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125
--a simple helper function which is too small to move into movement.lua
local quick_rotate_45 = function(self,dtime)
self.yaw = self.yaw + THIRTY_SECONDTH_PI
if self.yaw > DOUBLE_PI then
self.yaw = self.yaw - DOUBLE_PI
end
end
--[[ --[[
_ _ _ _
| | | | | | | |
@ -43,14 +52,6 @@ local cliff_check = function(self,dtime)
return free_fall return free_fall
end end
--a simple helper function which is too small to move into movement.lua
local quick_rotate_45 = function(self,dtime)
self.yaw = self.yaw + THIRTY_SECONDTH_PI
if self.yaw > DOUBLE_PI then
self.yaw = self.yaw - DOUBLE_PI
end
end
--check if a mob needs to jump --check if a mob needs to jump
local jump_check = function(self,dtime) local jump_check = function(self,dtime)
@ -101,9 +102,6 @@ end
-- states are executed here -- states are executed here
local land_state_execution = function(self,dtime) local land_state_execution = function(self,dtime)
--local yaw = self.object:get_yaw() or 0
if self.state == "stand" then if self.state == "stand" then
--do animation --do animation
@ -136,6 +134,7 @@ local land_state_execution = function(self,dtime)
local node_in_front_of = jump_check(self) local node_in_front_of = jump_check(self)
if node_in_front_of == 1 then if node_in_front_of == 1 then
mobs.jump(self) mobs.jump(self)
--turn if on the edge of cliff --turn if on the edge of cliff
@ -195,7 +194,27 @@ local swim_state_switch = function(self, dtime)
end end
--check if a mob needs to turn while swimming
local swim_turn_check = function(self,dtime)
local pos = self.object:get_pos()
pos.y = pos.y + 0.1
local dir = minetest_yaw_to_dir(self.yaw)
local collisionbox = self.object:get_properties().collisionbox
local radius = collisionbox[4] + 0.5
vector_multiply(dir, radius)
local test_dir = vector.add(pos,dir)
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
return(green_flag_1)
end
--this is going to need some more logic gates because birds can flop around --this is going to need some more logic gates because birds can flop around
--REMOVE THIS - just dump mobs.flop into where this was
local flop = function(self,dtime) local flop = function(self,dtime)
mobs.flop(self) mobs.flop(self)
end end
@ -243,11 +262,6 @@ local swim_state_execution = function(self,dtime)
--do animation --do animation
--mobs.set_mob_animation(self, "stand") --mobs.set_mob_animation(self, "stand")
--set the velocity of the mob
--mobs.set_velocity(self,0)
--print("standing")
mobs.set_swim_velocity(self,0) mobs.set_swim_velocity(self,0)
elseif self.state == "swim" then elseif self.state == "swim" then
@ -268,6 +282,13 @@ local swim_state_execution = function(self,dtime)
end end
--do a quick turn to make mob continuously move
--if in a fish tank or something
if swim_turn_check(self,dtime) then
quick_rotate_45(self,dtime)
end
mobs.set_swim_velocity(self,self.walk_velocity) mobs.set_swim_velocity(self,self.walk_velocity)
end end
--flop around if not inside swim node --flop around if not inside swim node
@ -298,10 +319,6 @@ mobs.mob_step = function(self, dtime)
return false return false
end end
--print(self.object:get_yaw())
--swimming --swimming
if self.swim then if self.swim then
swim_state_switch(self, dtime) swim_state_switch(self, dtime)