I'm trying to make a method that will draw a line which shows where the player will land, I don't know how to do that right. The current code I have draws it wrong.
Here it is:
void ShowTrajectory()
{
line.enabled = true;
Vector3 startPos = line.transform.position; //transform.position;
Vector3 startVel = playerTransform.forward * m.defaultSpeed + Vector3.up * (m.jumpForce / m.rb.mass / 1000); //if i won't divide this number the line goes to the sky
Vector3[] points = new Vector3[resolution];
points[0] = startPos;
for (int i = 1; i < resolution; i++)
{
float t = i * timeStep;
Vector3 point = startPos + startVel * t + 0.5f * Physics.gravity * t * t;
// check for collision
if (Physics.Raycast(points[i - 1], point - points[i - 1], out RaycastHit hit, (point - points[i - 1]).magnitude, collisionMask))
{
points[i] = hit.point;
line.positionCount = i + 1;
line.SetPositions(points);
return;
}
points[i] = point;
}
line.positionCount = resolution;
line.SetPositions(points);
}