Merge pull request 'Creeper should not walk to player if it does not have line of sight. Mob shouldn't look at player it does not have line of sight to.' (#3807) from line_of_sight_improvement into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3807
This commit is contained in:
ancientmarinerdev 2023-06-21 20:22:24 +00:00
commit 5806dd6017
2 changed files with 18 additions and 9 deletions

View File

@ -873,10 +873,13 @@ function mob_class:do_states_attack (dtime)
local dist = vector.distance(p, s)
if self.attack_type == "explode" then
local vec = { x = p.x - s.x, z = p.z - s.z }
yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate
if p.x > s.x then yaw = yaw +math.pi end
yaw = self:set_yaw( yaw, 0, dtime)
if target_line_of_sight then
local vec = { x = p.x - s.x, z = p.z - s.z }
yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate
if p.x > s.x then yaw = yaw +math.pi end
yaw = self:set_yaw( yaw, 0, dtime)
end
local node_break_radius = self.explosion_radius or 1
local entity_damage_radius = self.explosion_damage_radius
@ -900,10 +903,10 @@ function mob_class:do_states_attack (dtime)
end
-- walk right up to player unless the timer is active
if self.v_start and (self.stop_to_explode or dist < self.reach) then
self:set_velocity( 0)
if self.v_start and (self.stop_to_explode or dist < self.reach) or not target_line_of_sight then
self:set_velocity(0)
else
self:set_velocity( self.run_velocity)
self:set_velocity(self.run_velocity)
end
if self.animation and self.animation.run_start then

View File

@ -316,8 +316,14 @@ local function who_are_you_looking_at (self, dtime)
local stop_look_at_player = stop_look_at_player_chance == 1
if self.attack or self.following then
self._locked_object = self.attack or self.following
if self.attack then
if not self.target_time_lost then
self._locked_object = self.attack
else
self._locked_object = nil
end
elseif self.following then
self._locked_object = self.following
elseif self._locked_object then
if stop_look_at_player then
--minetest.log("Stop look: ".. self.name)