Hi guys
I’m using smoothDamp to move between amounts of acceleration and braking on a vehicle. It’s my first game and I’ve not used smoothDamp before so I’m hoping someone can explain how I might influence the easing in and out of the transition between values.
Here is my current code (just the relevant bits):
float accelerate; // Calls Axis for right trigger
float accelerationFactor = 0.0f;
float currentSpeed = 0.0f;
float maxSpeed = 300.0f;
void FixedUpdate ()
{
// Basic movement
accelerate = Input.GetAxisRaw ("Fire2");
float newSpeed = Mathf.SmoothDamp(currentSpeed, maxSpeed * accelerate, ref accelerationFactor, 0.4f);
currentSpeed = newSpeed;
// Forward movement
rb.AddForce (transform.forward * currentSpeed);
I’ve read through the Unity documentation I could find on this and several tutorials or explanatory articles but I’m unclear on what exactly I need to adjust or add to control the easing.
I’m also not entirely clear on what the difference between the Velocity and SmoothTime variables are doing. I think the SmoothTime is controlling how quickly the old value updates to the new value and that Velocity is exposing the change in the values each frame (please someone correct me if I’m wrong) but I can’t work out how I might use these to change how the changes happen.
Any help much appreciated.