- Home /
Question by
DivinosDev · Sep 10, 2019 at 10:38 AM ·
linerendererline rendererdebug.drawline
How to make curved Debug.DrawLine in game view using LineRenderer
How can I make this curved projectile line using line renderer through script? I'm using Sebastian Lague's projectile script and he draws a line using Debug.DrawLine which is a gizmo and not visible in the build. I've used SetPosition but it doesn't seem to work as expected.
The Green line in the image is from the Debug.DrawLine and the red is the LineRenderer
void DrawPath()
{
LaunchData launchData = CalculateLaunchData();
Vector3 previousDrawPoint = ball.position;
int resolution = 30;
for (int i = 1; i <= resolution; i++)
{
float simulationTime = i / (float)resolution * launchData.timeToTarget;
Vector3 displacement = launchData.initialVelocity * simulationTime + Vector3.up * gravity * simulationTime * simulationTime / 2f;
Vector3 drawPoint = ball.position + displacement;
Debug.DrawLine(previousDrawPoint, drawPoint, Color.green);
//I want to replace this with a line renderer
lineRenderer.SetPosition(i, drawPoint);
previousDrawPoint = drawPoint;
}
}
On play I'm getting an LineRenderer.SetPosition index out of bounds! error
annotation-2019-09-10-160110.png
(80.1 kB)
Comment