I’m trying to generate a cone out of line renderers, but i’m struggling to figure out the direction of each line. My code works perfectly when my object has a Y rotation of 0 or 180 degrees, but as it turns the cone becomes more and more flat, turning into more of a 2D shape at 90 and 270 Y rotation. Here’s my code:
void DrawLine (Vector3 Di, int i)
{
if(Physics.Raycast(gameObject.transform.position, Di, out hit, MaxLenght))
{
line.SetPosition(i, gameObject.transform.position);
line.SetPosition(i+1, hit.point);
if(hit.transform.gameObject.name=="Player" && InvisScript.isInvis==false)
{
isAngry=true;
playerSpottedPosition=hit.point;
}
}
else {
line.SetPosition(i, gameObject.transform.position);
line.SetPosition(i+1, transform.position + Di*MaxLenght);
}
}
void Gen (int n)
{
int i;
isAngry = false;
for (i=0; i<n; i++) {
Vector2 alpha, r;
r.y = MaxR*Mathf.Cos(Mathf.Deg2Rad * i*360/n);
r.x = MaxR*Mathf.Sin(Mathf.Deg2Rad * i*360/n);
alpha.x = Mathf.Atan(r.x / MaxLenght) * Mathf.Rad2Deg;
alpha.y = Mathf.Atan(r.y / MaxLenght) * Mathf.Rad2Deg;
Vector3 Di = (Quaternion.Euler(alpha.x,alpha.y,0) * transform.forward).normalized;
DrawLine(Di, 2*i);
}
If I calculate the Z rotation (r.z = MaxRMathf.Sin(Mathf.Deg2Rad * i360/n); alpha.z = Mathf.Atan(r.z / MaxLenght) * Mathf.Rad2Deg) I get the same problem, just 45 degrees earlier. There’s something I’m missing about these axes…