forked from MineClone5/MineClone5
Give mobs 6 seconds of memory to prevent strange behavior when player hides behind something
This commit is contained in:
parent
807fb6966d
commit
b401b50c04
|
@ -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,
|
||||||
|
|
||||||
|
|
|
@ -899,23 +899,41 @@ 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
|
|
||||||
else
|
|
||||||
|
|
||||||
--reset states when coming out of hostile state
|
--no player in area
|
||||||
if self.attacking ~= nil then
|
elseif self.memory > 0 then
|
||||||
self.state_timer = -1
|
--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
|
||||||
|
self.memory = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
self.attacking = nil
|
if self.memory <= 0 then
|
||||||
|
|
||||||
|
--reset states when coming out of hostile state
|
||||||
|
if self.attacking ~= nil then
|
||||||
|
self.state_timer = -1
|
||||||
|
end
|
||||||
|
|
||||||
|
self.attacking = nil
|
||||||
|
self.memory = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue