Very likely theres some trigonometry to this, but i cant figure it out.
Heres an example of what im trying to accomplish. The cone is inside the viewing angle, the cube is not. And the sphere is the caster.
So has anyone done this before? and if so, how did you do it?
Thanks to hexagonius, this is resolved.
Solution :
public float min = -60f;
public float max = 60f;
bool InsideViewAngle(Vector3 point)
{
Vector3 dirVec = (point - transform.position).normalized;
float up = Vector3.Dot(transform.up, dirVec) * 90f;
float down = Vector3.Dot(-transform.up, dirVec) * 90f;
/*
* if player is below the object
* up will return -90 and down will return 90
*
* if player is on the same vertical level as the object :
* up and down will return 0
*
* if player is on top :
* up will return 90 and down will return -90
*/
//if up is greater than min(-60), and is less than max(60);
return up > minVertical && up < maxVertical;
}