Hi guys, help me , please
I Want to make conecast from my object to any point on circle in 3d space ,
I find such equatation :
To get a parametric equation follow this procedure.
- Let N be a unit normal vector for the plane.
- Let C be the circle center, and let R be the radius.
- Let U be a unit vector from C toward a point on the circle.
- Let V = N x U.
- Let A be the paramter.
- A point P is on the circle if…
P = C + R cos(A) U + R sin(A) V
So i write such functions but it works wrong , maybe beacuse i put wrong parameters at GetPointsOf3dCircle function. So functions scripting:
//position = gameobject.transform.position (from which i make conecast)
//direction = gameobject.transform.position.forward
public static RaycastHit[ ] ConeCastAll(this Physics physics, Vector3 position, Vector3 direction, float viewAngle, float viewAngleStep,float range, float circleAngleStep)
{
if (viewAngle <= 0|| circleAngleStep<=0)
{
return null;
}
var center = position + (direction.normalized * range);
List coneCastHitList = new List();
for (float j = viewAngle; j >= 0; j -= viewAngleStep)
{
var radius = range * Mathf.Tan(Mathf.Deg2Rad *j/ 2);
for (float i = 0f; i < 360.0f; i += circleAngleStep)
{
//I think here I put wrong parameters ,maybe N wrong and U wrong , but i dont know where to get correct
var N = center.normalized;
var U = direction.normalized;
var point = GetCirclePointIn3D(N, center, U, i * Mathf.Deg2Rad, radius);
RaycastHit hit;
if (Physics.Raycast(position, point, out hit, range))
{
Vector3 hitPoint = hit.point;
coneCastHitList.Add(hit);
Debug.DrawLine(position, hitPoint, Color.red, 0.1f);
}
}
}
RaycastHit[ ] coneCastHits = new RaycastHit[coneCastHitList.Count];
coneCastHits = coneCastHitList.ToArray();
return coneCastHits;
}
private static Vector3 GetCirclePointIn3D(Vector3 N, Vector3 circleCenter, Vector3 U, float angle, float radius)
{
var V = Vector3.Cross(N ,U);
var point = circleCenter + radius * Mathf.Cos(angle) * U + radius * Mathf.Sin(angle) * V;
return point;
}
Guys, I need your help,THANK YOU