- Home /
Question by
Njalinferno · Jul 29, 2021 at 12:56 PM ·
2d2d-platformerinterpolation
How to extend the curve created using quadratic interpolation?
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);
}
}
Comment