[≈ solved] Check if an object is in field of view?

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

[≈ solved] Check if an object is in field of view?

by AiTechEye » Mon Feb 20, 2017 21:30

Someone that know how to calculate / or know where to find code, to check if an object is in field of view?

I think it could be something to sneak behind mobs without to be detected.

Image
Attachments
fov.png
fov.png (5.35 KiB) Viewed 1377 times
Last edited by AiTechEye on Tue Feb 21, 2017 22:04, edited 1 time in total.
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Re: Check if an object is in field of view?

by octacian » Mon Feb 20, 2017 23:01

VanessaE in IRC wrote:there's a line-of-sight call or two in the API I think
https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2323


I decided not to wait for someone to see this and asked there too :P
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: Check if an object is in field of view?

by BrandonReese » Tue Feb 21, 2017 03:16

See if this can help. I think it's mostly on a two plane but it might work.

http://blog.wolfire.com/2009/07/linear- ... rs-part-2/
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

Re: Check if an object is in field of view?

by AiTechEye » Tue Feb 21, 2017 15:37

line-of-sight checks if something is blocking the view.

the tutorial at blog.wolfire.com works as long the bot is looking at same direction (weird), but was usefull.
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Check if an object is in field of view?

by stu » Tue Feb 21, 2017 21:43

AiTechEye wrote:Someone that know how to calculate / or know where to find code, to check if an object is in field of view?

I think it could be something to sneak behind mobs without to be detected.

It would be almost impossible to determine the exact FOV of any client/view mode. You could possibly make a reasonable approximation but that wouldn't help without a lot of complicated trigonometry. `minetest.line_of_sight` is about the best we've got right now, though I believe there is a PR for better ray-casting support.

If the mob checks the LOS towards you and if that is not blocked by a node then it can 'see' you.
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

Re: Check if an object is in field of view?

by AiTechEye » Tue Feb 21, 2017 21:49

After a few hours of googling and testing, i got this idea, and its a lot easier:
if the object is nearer then the position front of it

so its just to check if the player is front of the mob
Image

so you gets a viewfield that looks like this
Image

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
function is_front_of(pos1,pos2)
   local pos1=self.object:getpos()
   local pos2=ob:getpos()
   local l1=distance(pos1,pos2)
   local l2=distance(aliveai.pointat(self,1),pos2)
   return l1>l2
end

function distance(pos1,pos2)
   return math.sqrt((pos1.x-pos2.x)*(pos1.x-pos2.x) + (pos1.y-pos2.y)*(pos1.y-pos2.y)+(pos1.z-pos2.z)*(pos1.z-pos2.z))
end

function pointat(self,d)-- get position front of object
   local pos=self.object:getpos()
   local yaw=self.object:getyaw()
   d=d or 1
   local x =math.sin(yaw) * -d
   local z =math.cos(yaw) * d
   return {x=pos.x+x,y=pos.y,z=pos.z+z}
end
Attachments
poss1.png
poss1.png (874 Bytes) Viewed 1376 times
poss.png
poss.png (3.54 KiB) Viewed 1376 times
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Check if an object is in field of view?

by stu » Tue Feb 21, 2017 22:09

You really should use the built-in vector helpers, for distance especially. It still looks to me like a rather inefficient way to accomplish this, though I do not fully understand your requirements.
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

Re: [≈ solved] Check if an object is in field of view?

by AiTechEye » Tue Feb 21, 2017 22:39

i need them to this mod, but this easy version works too :-)

in my case its too late to use the helpers, because i had no idea there was such features in minetest when i started this mod project a few months ago.

https://forum.minetest.net/viewtopic.php?f=11&t=16083

minetest.line_of_sight checks if you are behind something, so you can hide behind flowers...
(im using a more useful function for that)
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 53 guests

cron