- Home /
Question by
lochan_vishwanath · Feb 10, 2021 at 12:38 PM ·
mathtrajectorytrigonometrypredictionphysics 2d
LineRender and Gizmos.DrawRay are showing different results for the same input values
I am supplying the same inputs for both Gizmos.DrawRay and my LineRender but the output lines dont match each other.
I want the resulting LineRender to draw the same line as my Gizmos.DrawRay
I have attached a picture for reference: Code:
void Update()
{
hit = Physics2D.CircleCast(transform.position, _radius, transform.up, 100f, ~(ignoreLayer));
if (hit)
{
currentHitObject = hit.transform.gameObject;
currentHitDistance = hit.distance;
hitdistance = hit.normal * -1;
}
else
{
currentHitObject = null;
currentHitDistance = maxDistance;
}
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.blue;
if(PEPrediction.Hitting && hit) Gizmos.DrawRay(hit.collider.transform.position, hitdistance * 10);
if (hit && renderLine)
{
Vector3[] normals = new Vector3[2];
normals[0] = hit.collider.transform.position;
normals[1] = hitdistance * 10;
UpdateLineVector(_normal, normals);
}
}
private void UpdateLineVector(LineRenderer lineRenderer, Vector3[] vectors)
{
lineRenderer.positionCount = vectors.Length;
lineRenderer.SetPositions(vectors);
}
ANY HELP IS APPRECIATED!!!
wrong-prediction.png
(95.8 kB)
Comment