Merge pull request 'Add line of sight calculations to the enderman' (#1481) from jordan4ibanez/MineClone2-MobTweaks:master into master

Reviewed-on: MineClone2/MineClone2#1481
This commit is contained in:
jordan4ibanez 2021-04-07 01:30:19 +00:00
commit 8ab9de74dc
1 changed files with 2 additions and 1 deletions

View File

@ -351,12 +351,13 @@ mobs:register_mob("mobs_mc:enderman", {
--calculate very quickly the exact location the player is looking --calculate very quickly the exact location the player is looking
--within the distance between the two "heads" (player and enderman) --within the distance between the two "heads" (player and enderman)
local look_pos = vector.new(player_pos.x, player_pos.y + player_eye_height, player_pos.z) local look_pos = vector.new(player_pos.x, player_pos.y + player_eye_height, player_pos.z)
local look_pos_base = look_pos
local ender_eye_pos = vector.new(enderpos.x, enderpos.y + 2.75, enderpos.z) local ender_eye_pos = vector.new(enderpos.x, enderpos.y + 2.75, enderpos.z)
local eye_distance_from_player = vector.distance(ender_eye_pos, look_pos) local eye_distance_from_player = vector.distance(ender_eye_pos, look_pos)
look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player)) look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player))
--if looking in general head position, turn hostile --if looking in general head position, turn hostile
if vector.distance(look_pos, ender_eye_pos) <= 0.4 then if minetest.line_of_sight(ender_eye_pos, look_pos_base) and vector.distance(look_pos, ender_eye_pos) <= 0.4 then
self.provoked = "staring" self.provoked = "staring"
self.attack = minetest.get_player_by_name(obj:get_player_name()) self.attack = minetest.get_player_by_name(obj:get_player_name())
break break