Hey guys, I am trying to make a more realistic visual cone for my AI. I think Ive got a reasonable system set up. But I am not sure how I can check if my player is inside the green area (see picture)!
If I know wheter or not the player is inside the green area, the rest is easy to find out!
Here is the code I am using inside OnTriggerStay to find the position of the player and the positions of the cone:
Vector3 dir = o.transform.position - head.position;
float a = Vector3.Angle(dir, transform.forward);
float d = Vector3.Distance(o.transform.position, head.position);
#region Sweetspot Debug
byte fov = (byte)120f; //TODO Make dynamic based on rendertextures cameras fov
float ssmp = 0f;
// float y = 0f; //TODO Store
float r1 = 10; //TODO Make public
float r2 = 16; //TODO Make public
float r3 = 20; //TODO Make public
float x = r3*Mathf.Sin(Mathf.Deg2Rad*(fov/6))/Mathf.Sin(Mathf.Deg2Rad*(180-(fov/3)));
Debug.Log(x);
Debug.DrawRay(transform.position, transform.right*r1, Color.red);
Debug.DrawRay(transform.position, -transform.right*r1, Color.red);
Ray ray0 = new Ray(transform.position, transform.right+transform.forward*Mathf.Rad2Deg/(fov/3));
Ray ray1 = new Ray(transform.position, -transform.right+transform.forward*Mathf.Rad2Deg/(fov/3));
Debug.DrawRay(transform.position, ray0.direction*r3, Color.cyan);
Debug.DrawRay(transform.position, ray1.direction*r3, Color.cyan);
Debug.DrawRay(transform.position, ray0.direction*x, Color.green);
Debug.DrawRay(transform.position, ray1.direction*x, Color.green);
Ray ray4 = new Ray(transform.position, (transform.right/4+transform.forward));
Ray ray5 = new Ray(transform.position, (-transform.right/4+transform.forward));
Ray ray2 = new Ray(transform.position, transform.right+transform.forward*Mathf.Rad2Deg/(fov/2));
Ray ray3 = new Ray(transform.position, -transform.right+transform.forward*Mathf.Rad2Deg/(fov/2));
Debug.DrawRay(transform.position, ray2.direction*r2, Color.yellow);
Debug.DrawRay(transform.position, ray3.direction*r2, Color.yellow);
#region Draw lines
Debug.DrawRay(transform.position, transform.forward*r3, Color.blue);
Debug.DrawRay(transform.position, transform.forward*r2, Color.yellow);
Debug.DrawRay(transform.position, transform.forward*r1, Color.red);
Debug.DrawLine(transform.right*r1, ray2.direction*r1, Color.red);
Debug.DrawLine(-transform.right*r1, ray3.direction*r1, Color.red);
Debug.DrawLine(ray2.direction*r1, ray4.direction*r1, Color.red);
Debug.DrawLine(ray3.direction*r1, ray5.direction*r1, Color.red);
Debug.DrawLine(ray4.direction*r1, transform.forward*r1, Color.red);
Debug.DrawLine(ray5.direction*r1, transform.forward*r1, Color.red);
Debug.DrawLine(ray2.direction*r2, ray4.direction*r2, Color.yellow);
Debug.DrawLine(ray3.direction*r2, ray5.direction*r2, Color.yellow);
Debug.DrawLine(ray4.direction*r2, transform.forward*r2, Color.yellow);
Debug.DrawLine(ray5.direction*r2, transform.forward*r2, Color.yellow);
Debug.DrawLine(ray0.direction*r3, ray4.direction*r3, Color.blue);
Debug.DrawLine(ray1.direction*r3, ray5.direction*r3, Color.blue);
Debug.DrawLine(ray4.direction*r3, transform.forward*r3, Color.blue);
Debug.DrawLine(ray5.direction*r3, transform.forward*r3, Color.blue);
Debug.DrawLine(ray4.direction*r3, ray0.direction*x, Color.green);
Debug.DrawLine(ray5.direction*r3, ray1.direction*x, Color.green);
#endregion
#endregion