I have a spherical rigidbody, and I have some code to calculate its landing point given its position and its velocity. This is what that looks like:
public Vector3 GetPredictedPointOnArc(Vector3 position, Vector3 velocity, float t)
{
Vector3 point = Vector3.zero;
point.y = 0.5f * Physics.gravity.y * (t * t) + velocity.y * t;
point.x = velocity.x * t;
point.z = velocity.z * t;
return point + position;
}
This is just done in a for loop for a set number of iterations, where each iteration raycasts towards the next. t represents how far to scan, and ideally is time.deltaTime.
This works to get a position, but how can i figure out the time it would take? what should i do?
This is the current code i'm using, but it's buggy and inaccurate:
time = (predictedLandingInfo.point.x - transform.position.x) / rb.velocity.x;