Hi everyone,
I am a beginner in Unity, coming from a web development background, and I have basic physics knowledge.
I am experimenting with a bike model and trying to learn how to use Lerp to update its velocity. However, I’m encountering an issue: when I go forward and then turn right, and then stop pressing any keys, the bike slides instead of stopping smoothly. It even seems to slide in the wrong direction.
Here is my current code for updating the bike’s velocity and rotation:
void Acceleration()
{
sphereRB.velocity = Vector3.Lerp(sphereRB.velocity, moveInput * maxSpeed * transform.forward, Time.fixedDeltaTime * acceleration);
}
void Steer()
{
transform.Rotate(0, steerInput * steerStrength * Time.fixedDeltaTime, 0, Space.World);
}
Here is the video demonstration
I have a few questions:
- How can I properly use Lerp for velocity to avoid the sliding issue?
- Do I need to use
InverseTransformDirection
to obtain the velocity in local coordinates and multiply them? This question specifically applies to the rotation.
I would appreciate any advice or suggestions. Thank you!