mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
Enderman use vectors to check distance between player and self
This commit is contained in:
parent
00db03320b
commit
9f7899c01a
@ -331,27 +331,30 @@ mobs:register_mob("mobs_mc:enderman", {
|
|||||||
for _,obj in pairs(minetest.get_connected_players()) do
|
for _,obj in pairs(minetest.get_connected_players()) do
|
||||||
-- Check if they are looking at us.
|
-- Check if they are looking at us.
|
||||||
local player_pos = obj:get_pos()
|
local player_pos = obj:get_pos()
|
||||||
local look_dir_not_normalized = obj:get_look_dir()
|
if vector.distance(enderpos, player_pos) <= 64 then
|
||||||
local look_dir = vector.normalize(look_dir_not_normalized)
|
|
||||||
local look_pos = vector.new({x = look_dir.x+player_pos.x, y = look_dir.y+player_pos.y + 1.5, z = look_dir.z+player_pos.z}) -- Arbitrary value (1.5) is head level according to player info mod.
|
local look_dir_not_normalized = obj:get_look_dir()
|
||||||
-- Cast up to 64 to see if player is looking at enderman.
|
local look_dir = vector.normalize(look_dir_not_normalized)
|
||||||
for n = 1,64,.25 do
|
local look_pos = vector.new({x = look_dir.x+player_pos.x, y = look_dir.y+player_pos.y + 1.5, z = look_dir.z+player_pos.z}) -- Arbitrary value (1.5) is head level according to player info mod.
|
||||||
local node = minetest.get_node(look_pos)
|
-- Cast up to 64 to see if player is looking at enderman.
|
||||||
if node.name ~= "air" then
|
for n = 1,64,.25 do
|
||||||
break
|
local node = minetest.get_node(look_pos)
|
||||||
end
|
if node.name ~= "air" then
|
||||||
if look_pos.x-1<enderpos.x and look_pos.x+1>enderpos.x and look_pos.y-2.89<enderpos.y and look_pos.y-2>enderpos.y and look_pos.z-1<enderpos.z and look_pos.z+1>enderpos.z then
|
break
|
||||||
self.provoked = "staring"
|
|
||||||
self.attack = minetest.get_player_by_name(obj:get_player_name())
|
|
||||||
break
|
|
||||||
else
|
|
||||||
if self.provoked == "staring" then
|
|
||||||
self.provoked = "broke_contact"
|
|
||||||
end
|
end
|
||||||
|
if look_pos.x-1<enderpos.x and look_pos.x+1>enderpos.x and look_pos.y-2.89<enderpos.y and look_pos.y-2>enderpos.y and look_pos.z-1<enderpos.z and look_pos.z+1>enderpos.z then
|
||||||
|
self.provoked = "staring"
|
||||||
|
self.attack = minetest.get_player_by_name(obj:get_player_name())
|
||||||
|
break
|
||||||
|
else
|
||||||
|
if self.provoked == "staring" then
|
||||||
|
self.provoked = "broke_contact"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
look_pos.x = look_pos.x + (.25 * look_dir.x)
|
||||||
|
look_pos.y = look_pos.y + (.25 * look_dir.y)
|
||||||
|
look_pos.z = look_pos.z + (.25 * look_dir.z)
|
||||||
end
|
end
|
||||||
look_pos.x = look_pos.x + (.25 * look_dir.x)
|
|
||||||
look_pos.y = look_pos.y + (.25 * look_dir.y)
|
|
||||||
look_pos.z = look_pos.z + (.25 * look_dir.z)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- TAKE AND PLACE STUFF BEHAVIOUR BELOW.
|
-- TAKE AND PLACE STUFF BEHAVIOUR BELOW.
|
||||||
|
Loading…
Reference in New Issue
Block a user