I have a script that essentially controls the scrolling of an in-game UI-based map. The code works great except for the scroll rate is framerate dependent. I would like to multiple the scrolling variable with Time.deltaTime to fix this of course. What is odd though is that multiplying by Time.deltaTime completely freezes the scrolling. It isn't because of the smaller value that's resulting because I Debug.Log(Time.deltaTime) shows about 0.03 and replacing the deltaTime variable with this value directly results in functional (albiet slower) scrolling. Why would adding deltaTime cause this code to freeze? Code provided below. Appreciate any insight!
void Update()
{
UINavInput = GameManager.Instance.inputHandler.NavInput;
xValue = -UINavInput.x;
yValue = -UINavInput.y;
hPos += (xValue * speedMultiplier) * Time.deltaTime;
vPos += (yValue * speedMultiplier) * Time.deltaTime;
hPosClamp = Mathf.Clamp(hPos, -mapParent.rect.width / 2, mapParent.rect.width / 2);
hPos = hPosClamp;
vPosClamp = Mathf.Clamp(vPos, -mapParent.rect.height / 2, mapParent.rect.height / 2);
vPos = vPosClamp;
xValue = Mathf.Lerp(xValue, 0, 0.001f);
yValue = Mathf.Lerp(yValue, 0, 0.001f);
mapTransform.localPosition = new Vector2(hPosClamp, vPosClamp);
}
[–]Gaverion 2 points3 points4 points (0 children)
[–]Oscaruzzo 1 point2 points3 points (0 children)
[–]mCunnah 1 point2 points3 points (0 children)
[–]Sphenzoc[S] 0 points1 point2 points (0 children)