I am working on approximating the physics involved with a disc golf disc and I’m having trouble transitioning from the turn phase to the fade phase of the disc’s flight. Assume Right Hand/Back Hand (RHBH) throws.
In FixedUpdate I apply a leftward/rightward force to the disc, based on the turn and fade values of the disc. So if a disc has a turn rating of -2 and a fade rating of 1 I would apply a rightward force of the abs of the turn rating, and then a negative (leftward) force of the fade rating, based on the Y velocity of the disc’s rigidbody.
In code it looks like this:
disc = this.gameObject;
discRB = disc.GetComponent<Rigidbody>();
// Turn and fade ratings are pulled from values I can modify in the editor.
fadeVelocity = new Vector3(-fadeRating, 0f, 0f);
turnVelocity = new Vector3(turnRating, 0f, 0f);
var _currentVelocityY = discRB.velocity.y;
/* While the Y velocity is sufficiently large, apply the turning effect as a force to the disc. When Y velocity gets closer to zero, begin lerping between the turn and fade force values. Finally, apply the fade effect as the Y velocity become larger in the negative direction. */
if (_currentVelocityY > 2.5f)
{
discRB.AddRelativeForce(turnVelocity);
}
else if (_currentVelocityY >= -2.5f && _currentVelocityY <= 2.5f)
{
lerpVelocity = Vector3.Lerp(turnVelocity, fadeVelocity, 0.4f);
discRB.AddRelativeForce(-lerpVelocity);
fixedFrameCount++;
}
else if (_currentVelocityY < -2.5f)
{
discRB.AddRelativeForce(fadeVelocity * (1f + fadeFrameCount / 50f));
fadeFrameCount++;
Debug.Log(fadeFrameCount);
}
The issue I’m having is that the transition between turn and fade is rather abrupt, rather than gradual. I’m certain it’s to do with the Vector3.Lerp t value, I’m just not sure how to go about modifying this to slow the turn effect while ramping up the fade effect.
Am I using Lerp correctly here? And, what could I do to smooth out the transition between the turn and fade phases?