1
0
Fork 0

Smooth out mob cliff check and check if falling before cliff check

This commit is contained in:
jordan4ibanez 2021-04-16 15:39:39 -04:00
parent 2486ffef11
commit 6c5393427f
1 changed files with 12 additions and 3 deletions

View File

@ -12,17 +12,26 @@ local minetest_line_of_sight = minetest.line_of_sight
local state_list_wandering = {"stand", "walk"} local state_list_wandering = {"stand", "walk"}
local DOUBLE_PI = math.pi * 2 local DOUBLE_PI = math.pi * 2
local EIGHTH_PI = DOUBLE_PI * 0.125 local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125
--this is basically reverse jump_check --this is basically reverse jump_check
local cliff_check = function(self,dtime) local cliff_check = function(self,dtime)
--mobs will flip out if they are falling without this
if self.object:get_velocity().y ~= 0 then
return false
end
local pos = self.object:get_pos() local pos = self.object:get_pos()
pos.y = pos.y + 0.1
local dir = minetest_yaw_to_dir(self.yaw) local dir = minetest_yaw_to_dir(self.yaw)
local collisionbox = self.object:get_properties().collisionbox local collisionbox = self.object:get_properties().collisionbox
local radius = collisionbox[4] + 0.5 local radius = collisionbox[4] + 0.5
dir = vector_multiply(dir,radius)
local free_fall, blocker = minetest_line_of_sight( local free_fall, blocker = minetest_line_of_sight(
{x = pos.x + dir.x, y = pos.y, z = pos.z + dir.z}, {x = pos.x + dir.x, y = pos.y, z = pos.z + dir.z},
{x = pos.x + dir.x, y = pos.y - self.fear_height, z = pos.z + dir.z}) {x = pos.x + dir.x, y = pos.y - self.fear_height, z = pos.z + dir.z})
@ -32,7 +41,7 @@ end
--a simple helper function which is too small to move into movement.lua --a simple helper function which is too small to move into movement.lua
local quick_rotate_45 = function(self,dtime) local quick_rotate_45 = function(self,dtime)
self.yaw = self.yaw + EIGHTH_PI self.yaw = self.yaw + THIRTY_SECONDTH_PI
if self.yaw > DOUBLE_PI then if self.yaw > DOUBLE_PI then
self.yaw = self.yaw - DOUBLE_PI self.yaw = self.yaw - DOUBLE_PI
end end