- Home /
Understanding smoothTime in Mathf.SmoothDamp
I have some script on my camera which switches the focus of the camera between 2 characters in a 2D platformer. To do this I have a raw value which switches between the position of each one when I push a button (target position), then I use Mathf.SmoothDamp to transition smoothly. If I use SmoothDamp permanently the camera jitters when the characters are moving, so my solution is to only use the SmoothDamp when I push the button and then stop it when the camera has reached the position.
The problem I have is detecting when the camera is in position. I have tried doing it if the target position == current position, but it never seems to match up, even when the camera is still. The closest I get with this method is to work out the difference between the target position and the current position, and stop SmoothDamp when they are < 0.1 difference. This works OK if the characters are still, but if they are moving when you push the button, it won't stop until the character is sill.
I have tried to invoke the stop on a timer, but the problem there is that it takes longer to move if the characters are further apart. What I can't understand is how the smoothTime relates to how long it actually takes to move. In the documentation it say "Approximately the time it will take to reach the target.", but what is the actual calculation? If I know how long it takes, I can stop it after that amount of time.
How can I work out how long it will take knowing the distance and smoothTime?
Or is there a better solution to my problem? Maybe there is a way of making the camera smooth with SmoothDamp on all the time.
Cheers Kevin
Your answer
Follow this Question
Related Questions
2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer
Camera.ScreenToWorldPoint with Perspective camera 1 Answer
How can I fix this screen wrapping? 1 Answer
I want the camera to follow just the X coordinate of the player. 1 Answer
2D Orthographic Main Camera and UI 0 Answers