Give mobs 6 seconds of memory to prevent strange behavior when player hides behind something

This commit is contained in:
jordan4ibanez 2021-04-24 21:15:42 -04:00
parent 807fb6966d
commit b401b50c04
2 changed files with 27 additions and 7 deletions

View File

@ -328,6 +328,8 @@ function mobs:register_mob(name, def)
minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath
memory = 0, -- memory timer if chasing/following
--for spiders --for spiders
always_climb = def.always_climb, always_climb = def.always_climb,

View File

@ -899,16 +899,32 @@ mobs.mob_step = function(self, dtime)
--go get the closest player --go get the closest player
if attacking then if attacking then
self.memory = 6 --6 seconds of memory
--set initial punch timer --set initial punch timer
if self.attacking == nil then if self.attacking == nil then
if self.attack_type == "punch" then if self.attack_type == "punch" then
self.punch_timer = -1 self.punch_timer = -1
end end
end end
self.attacking = attacking self.attacking = attacking
--no player in area --no player in area
elseif self.memory > 0 then
--try to remember
self.memory = self.memory - dtime
--get if memory player is within viewing range
if self.attacking and self.attacking:is_player() then
local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos())
if distance > self.view_range then
self.memory = 0
end
--out of viewing range, forget em
else else
self.memory = 0
end
if self.memory <= 0 then
--reset states when coming out of hostile state --reset states when coming out of hostile state
if self.attacking ~= nil then if self.attacking ~= nil then
@ -916,6 +932,8 @@ mobs.mob_step = function(self, dtime)
end end
self.attacking = nil self.attacking = nil
self.memory = 0
end
end end
end end