Need help debugging speed difference in different UI elements
Heyo! Coming here after a couple hours scratching my head at this. I'm using a custom lerp function that I created for lerping between two UI elements. It's actually not completely linear, as I'm trying to do a distance lerp that also takes into account the scale of the object. Here, I'm trying to get visualTab (a rect) to place itself at the location of the current button and also match its scale over time.
foreach (RectTransform rt in btnRects) // loop through my buttons
{
if (rt.gameObject == currentButton && (rt.sizeDelta != visualTab.sizeDelta || rt.position != visualTab.position)) // grab the current button, and check that it isn't already where the visual tab is at
{
Vector2 scaleDiff = rt.sizeDelta - visualTab.sizeDelta; // difference between the scale of the two objects
visualTab.sizeDelta += scaleDiff; // scale along that vector
Vector3 dir = rt.position - visualTab.position; // get the direction of the object from the visual tab
if (dir.sqrMagnitude < 100) visualTab.position = rt.position; // under a threshold, place the object at the visualtab's location
else
{
visualTab.position += dir.normalized * .8f * Time.fixedDeltaTime * Mathf.Clamp((dir.sqrMagnitude * .005f), 50, 300); // clamped between 50 and 300, move toward the object using the square magnitude of the direction, causing a lerp-like functionality that slows down when closer, and speeds up when further.
}
}
}
This is all well and good on my main UI tab interface. However, on a similar tab interface that is 50% smaller in horizontal scale, the speeds are completely different. As far as I can tell, the scale of my interface shouldn't interfere with this. The difference in scale for the two visualTabs is 50 points, and on a 1000+ width interface surely that is not the cause of this discrepancy. Hopefully someone can provide some insight!
Your answer
Follow this Question
Related Questions
interpolating to a non fixed position 0 Answers
Interpolated movement in a circle 1 Answer
Help with recttransform lerp , lags on mobile not on pc. 1 Answer
What exactly does Mathf.InverseLerp() do? 4 Answers
Smooth camera to target Y-height 3 Answers