Announcement
Collapse
No announcement yet.
AI View Field
Collapse
X

You could try using a line or possible sphere trace to the player. You may have to make sure your view field meshes does not interfere with the trace by either making sure it does not have collision or by making it use a channel other than what you are tracing against (if you need it for some collision purpose).Ryan Brucks
Principal Technical Artist, Epic Games

Originally posted by RyanB View PostYou could try using a line or possible sphere trace to the player. You may have to make sure your view field meshes does not interfere with the trace by either making sure it does not have collision or by making it use a channel other than what you are tracing against (if you need it for some collision purpose).Attached Files
Comment

You could use a multi box and then check the cone angle of each of your hits.
You would check the tangent of each hit by transforming it into the local box space and checking the cone by comparing the distance from the forward axis (opposite) and the length along the forward axis (adjacent). Since tangent = opposite / adjacent, by dividing those two you can reject hits based on a threshold that is calculated as tan(angle). Doing the tan in the precaulation phase (like in construction script) will make the resulting math much faster since you won't be doing any trig, only a few dot products, additions and division.
ie for a 45 degree FOV cone you would use the half angle (in order to get 2 right triangles out of it) which is 22.5. The tangent of 22.5 is 0.414 so you would get the distance from the player along the cone axis (adjacent, could be solved as the length of the Z channel after transforming into the local box space) and the distance from the X axis (opposite, which could be solved as the length of the 2d XY vector by multiplying by 1,1,0 after transforming into the local box space). Then do opposite/adjacent and if its less than 0.414, the hit will be within a 45 degree FOV cone (or 22.5 degree half angle).
btw when I say 'local box space' I mean a space where the forward vector becomes the Z because it makes the other math a bit easier but you could solve it however you want.Last edited by RyanB; 12292015, 08:00 PM.Ryan Brucks
Principal Technical Artist, Epic Games
Comment

Depending on how many objects are in the scene that you're looking for, a mathematical cone & distance check might even be faster than any collision shapes at all
You'd be surprised at how fast iterating an array of objects can be!Everything @ Stormtide Games  Snr Programmer @ Black Matter Pty.
Twitter  YouTube  Tutorials and Resources: jambax.co.uk
Games: Satellite Command  Hell Let Loose  Project Orion  Eclipse
Marketplace: Sparse Grid Plugin  Export PNG
Comment

Originally posted by RyanB View PostYou could use a multi box and then check the cone angle of each of your hits.
You would check the tangent of each hit by transforming it into the local box space and checking the cone by comparing the distance from the forward axis (opposite) and the length along the forward axis (adjacent). Since tangent = opposite / adjacent, by dividing those two you can reject hits based on a threshold that is calculated as tan(angle). Doing the tan in the precaulation phase (like in construction script) will make the resulting math much faster since you won't be doing any trig, only a few dot products, additions and division.
ie for a 45 degree FOV cone you would use the half angle (in order to get 2 right triangles out of it) which is 22.5. The tangent of 22.5 is 0.414 so you would get the distance from the player along the cone axis (adjacent, could be solved as the length of the Z channel after transforming into the local box space) and the distance from the X axis (opposite, which could be solved as the length of the 2d XY vector by multiplying by 1,1,0 after transforming into the local box space). Then do opposite/adjacent and if its less than 0.414, the hit will be within a 45 degree FOV cone (or 22.5 ...
Comment
Comment