Search Issue Tracker
Won't Fix
Votes
0
Found in
2019.4
2020.3
2020.3.14f1
2021.1
2021.2
2022.1
Issue ID
1353189
Regression
No
SmoothDamp function does not reach it's target smoothly when smoothTime value is changed before the smoothing ends
Steps to reproduce:
1. Open users attached project
2. Open Smoothing Issue/Press Play scene
3. Enter the Play Mode
4. Observe Cubes movement in the Game View
Expected result: Cube smoothly stops on the left side
Actual result: Cube comes to a solid stop on the left side
Reproducible with: 2019.4.29f1, 2020.3.16f1, 2021.1.17f1, 2021.2.0b7, 2022.1.0a5
Note: Reproducible with both Mathf.SmoothDamp and Vector3.SmoothDamp
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on MonoBehaviour::CallMethodIfAvailable when performing various actions
- Incorrect rotations on bones when importing FBX animations with a Humanoid Rig
- Render Graph Viewer “Pass List” section is flickering when resizing vertically and the Render Graph Viewer window is docked
- Render Graph Viewer Capture button plays the click animation but does not do anything when the Capture button is pressed with the “Enter” key on the keyboard
- UI Builder Scrollview is unable to scroll all the way down when the window is downsized vertically
Resolution Note:
We understand that SmoothDamp doesn't work in that particular case. But since there is a lot of other projects relying on this method to works, changing this behavior could be problematic for those projects.
Unity SmoothDamp method is based on the book Game Programming Gems 4 Chapter 1.10 which has the same behavior and problem as Unity's SmoothDamp.
The best solution we can provide is to write your own version of smooth damp for your project if the one provided by Mathf doesn't work as expected for you.
You can use this code as an example:
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
{
// Based on Game Programming Gems 4 Chapter 1.10
smoothTime = Mathf.Max(0.0001F, smoothTime);
float omega = 2F / smoothTime;
float x = omega * deltaTime;
float exp = 1F / (1F + x + 0.48F * x * x + 0.235F * x * x * x);
float change = current - target;
float originalTo = target;
// Clamp maximum speed
float maxChange = maxSpeed * smoothTime;
change = Mathf.Clamp(change, -maxChange, maxChange);
target = current - change;
float temp = (currentVelocity + omega * change) * deltaTime;
currentVelocity = (currentVelocity - omega * temp) * exp;
float output = target + (change + temp) * exp;
return output;
}