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

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 local stop_look_at_player = stop_look_at_player_chance == 1
if self.attack or self.following then if self.attack then
self._locked_object = self.attack or self.following 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 elseif self._locked_object then
if stop_look_at_player then if stop_look_at_player then
--minetest.log("Stop look: ".. self.name) --minetest.log("Stop look: ".. self.name)