I am attempting to use quadratic interpolation in order to throw a rock at the player's position. The rock simply follows the curve. However, if the player moves, the rock begins to loop and starts back at its original position. I have stopped the rock following the curve once it reaches the end of the curve and add force to the rock's rigidbody but it only works in specific examples. I was wondering if there was a way to extend the curve so the rock hits the ground and destroys itself using the code I already have. The code I am using is below. Thanks in advance. The code is below.
Quadratic Interpolation Code (it is run every frame)
private void FollowQuadraticPath()
{
interpolateAmount = (interpolateAmount + Time.deltaTime) % 1f;
pointAB.transform.position = Vector3.Lerp(transformerPosition, throwHeightPosition, interpolateAmount);
pointBC.transform.position = Vector3.Lerp(throwHeightPosition, playerPosition, interpolateAmount);
transform.position = Vector3.Lerp(pointAB.transform.position, pointBC.transform.position, interpolateAmount);
}
Damage
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.GetComponent<PlayerHealth>())
{
Destroy(pointABInstance);
Destroy(pointBCInstance);
collision.gameObject.GetComponent<PlayerHealth>().DealDamage(damage);
Destroy(gameObject);
}
else
{
Destroy(pointABInstance);
Destroy(pointBCInstance);
Destroy(gameObject);
}
}
This is what I want to happen. Pretending the player had moved, the rock would continue and hit the ground past the player point.
Instead, once again pretending the player wasn't there, the object is destroyed before it reaches the ground
Edit: Check comments of the answer for the solution I used