- Home /
SmoothDamp: reference velocity always 0
I am trying to get a RectTransform to slide from its current position to a destination position. For some reason, it works perfectly fine, except when the scene is loaded using SceneManager.LoadScene(). Once the scene loads up again, the velocity is always 0. Nothing is modifying it but the SmoothDamp function.
void Update () {
if (rectTransform.anchoredPosition.x != destination) {
float x = Mathf.SmoothDamp (rectTransform.anchoredPosition.x, destination, ref vel, transitionTime);
rectTransform.anchoredPosition = new Vector2 (x, rectTransform.anchoredPosition.y);
}
}
The destination is set by another script. There is a static reference to this script, which is called MenuTransition.
public static MenuTransition menuTransition; //set on Awake() to be this script
private float vel = 0;
Again, absolutely no issues until the scene is loaded again through script. Anybody have ideas as to why the vel value is always 0?
Your answer
![](https://koobas.hobune.stream/wayback/20220612082338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SmoothDamp won't reach its target 1 Answer
Player is not moving 0 Answers
How to measure Speed? 2 Answers
How to control easing in Mathf.smoothDamp? 1 Answer
Mathf.Clamp() or your own Clamp fn, which is better? 1 Answer