#Lerp
1 messages · Page 1 of 1 (latest)
- You can use https://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.html, if third parameter is
2 * Time.deltaTimeit’ll increase 2 units every second - For 2, you have to use lerp correctly. The third parameter represents the percentage from a to b (.5 is 50% from a to b). You have to store the time passed and divide it by total time
timePassed += Time.deltaTime;
float t = timePassed / 3; // accelerates to maxThrust in 3 seconds
float thrust = Mathf.Lerp(initialThrust, maxThrust, t);```
This video is pretty good
https://youtu.be/MyVY-y_jK1I
In this Unity game development tutorial we're going to look at the mathematical function, Lerp, or linear interpolation.
This function allows us to linearly interpolate between two values, and is most commonly used for changing values over a period of time.
While its usage is really common in Unity, it's quite often misunderstood, and can easi...
@thick pebble
Um
Could you help me here a little more
private void CalculateSteering()
{
if (steerLeft)
{
steeringAcceleration -= Time.fixedDeltaTime;
if (steeringAcceleration < -steeringTime)
steeringAcceleration = -steeringTime;
}
if (steerRight)
{
steeringAcceleration += Time.fixedDeltaTime;
if (steeringAcceleration > steeringTime)
steeringAcceleration = steeringTime;
}
if (!steerLeft && !steerRight)
{
if (steeringAcceleration > 0)
{
steeringAcceleration -= Time.fixedDeltaTime;
if (steeringAcceleration < 0)
steeringAcceleration = 0f;
}
else
{
steeringAcceleration += Time.fixedDeltaTime;
if (steeringAcceleration > 0)
steeringAcceleration = 0f;
}
}
float steering = Mathf.Lerp(0, maxSteering, Mathf.Abs(steeringAcceleration) / steeringTime);
rb.AddRelativeTorque(new Vector3(0f, steering * Mathf.Sign(steeringAcceleration), 0f), ForceMode.Acceleration);
}
@deft plank The ship will never turn left
Not sure if there is a better way to do this to avoid all the IFs
make steering negative if you want it to turn left

