#Lerp

1 messages · Page 1 of 1 (latest)

deft plank
#
  1. You can use https://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.html, if third parameter is 2 * Time.deltaTime it’ll increase 2 units every second
  2. 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...

▶ Play video
#

@thick pebble

thick pebble
#

Thank you very much, I'll check it out in a sec

thick pebble
#

Both solutions work perfectly

#

Thank you very much @deft plank perfecto

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

deft plank
thick pebble
#

Ok, let me try

#

This one is tricky