Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a vision cone in unity

I am attempting to implement a boids flocking model in unity.

I have managed to implement steering behaviours (separate, align, cohere) but I am currently using a fixed radius from the agent to define its neighbourhood (essentially a bubble around the agent). However, what I need to implement is a vision cone like the one detailed in this image:

boids vision cone

Im unsure how I could implement this in unity. Could someone point me in the correct direction?

To add clarity, what I want to do is detect all other agents in a vision cone, but I'm unsure how to implement it. Currently I am just detecting all agents within a distance, though I need to ignore the agents behind the one doing detecting ( like in the picture) I'm not looking to visualise it, just detect the agents in that defined neighbourhood.

thanks

like image 579
Chris Headleand Avatar asked Nov 01 '22 22:11

Chris Headleand


1 Answers

Detect all the agents in the circle, then check for every one of those the Vector3.Angle() between transform.forward and the direction to the agent.
(the direction from vector A to B is just B-A)

like image 151
kat0r Avatar answered Nov 08 '22 08:11

kat0r