Question by
hellojbb1234 · Feb 09, 2017 at 03:58 PM ·
linerenderercalculate
How do i make the line more smooth and accurate?
So I am calculating the trajectory of an object that will orbit something. So far it is going well I have gotten it to point in roughly the correct orbit. now I want it to smooth out an actually follow it before hand instead of just being blocky and being way to far out. Don't say it is the linerenderer's fault I put 20 points in.
public void CalculateLine(Vector3 oldPos)
{
Vector3 heading = oldPos - Input.mousePosition;
var distance = heading.magnitude;
var direction = heading / distance;
Vector3 FutPoints = new Vector3(heading.x / 7.5f, heading.y / 7.5f, 0);
thisLineRend.numPositions = 20;
var points = new Vector3[thisLineRend.numPositions];
Debug.Log("Calculating");
thisLineRend.SetPosition(0, transform.position);
thisLineRend.SetPosition(1, FutPoints);
testTri /= 9.8f;
for(int i = 2; i < thisLineRend.numPositions; i++)
{
testTri += FutPoints;
f = 1 * 2 / Vector3.Distance(testTri, gravityLinePre.gameObject.transform.position);
testTri.x = f * -9.8f;
testTri.y = f * -9.8f;
thisLineRend.SetPosition(i, new Vector3(testTri.x, testTri.y, transform.rotation.z));
}
}
Comment