mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-24 20:03:45 +01:00
Add line of sight calculations to the enderman
This commit is contained in:
parent
56f94af6ce
commit
acd2b8e691
@ -351,12 +351,13 @@ mobs:register_mob("mobs_mc:enderman", {
|
||||
--calculate very quickly the exact location the player is looking
|
||||
--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_base = look_pos
|
||||
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)
|
||||
look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player))
|
||||
|
||||
--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.attack = minetest.get_player_by_name(obj:get_player_name())
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user