2d Lerp and UI Issues

Updated on April 24, 2018 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on April 24, 2018

As seen in the video, lerp moves past its max point and ui lines get thinner and disappear when screen resolution is changed. Any suggestions on how to fix this?

https://www.youtube.com/watch?v=i4xlICwQLyo

Snippet
public static IEnumerator Lerp(this GameObject obj, float maximum, bool pingpong = false)
{
    float currentPos = obj.transform.position.y;
    float maxPos = currentPos * maximum;
 
    while (true)
    {
        // animate the position of the game object...
        obj.transform.position = new Vector2(obj.transform.position.x, Mathf.Lerp(currentPos, maxPos, t));
 
        // .. and increate the t interpolater
        t += 0.5f * Time.deltaTime;
 
        // in the opposite direction.
        if (t > 1.0f)
        {
            float temp = maxPos;
            maxPos = currentPos;
            currentPos = temp;
            t = 0;
 
        }
        yield return null;
 
    }
}
  • Liked by
Reply
2 on April 24, 2018

Does this still happen when you don’t resize the screen while the game is running?

Remember, you have saved numbers in the script when the screen was a certain size. If you change it half way through, of course it’s gonna go off the screen. It’s trying to get to the point you told it to go to. Now that the screen is smaller, that point is off the screen.

One solution is to use an empty transform that the object lerps to instead of some set distance. That way, as long as the object is properly anchored on the screen, the action will look the same, even if the screen size changes.

Any particular reason you’re doing it like this instead of just using Vector2.Lerp?

 

Edit: also make sure your canvas is set to scale with screen size, and isn’t set to the default constant pixel size.

Edit2: alternatively you could make this action an animation. Again, as long as the screen anchors are good, it should work at any scale and even changing ones.

Helpful
on April 24, 2018

Thanks that game object transform is a good idea. As for the canvas, its already set to scale with UI, the issue is with the graphics, its vector based, no compression,point filter and 500 PPU, it still glitches when scaled down in the scene view 

Wise
on April 24, 2018

Then yea, I would use a target transform, or make it an animation.

 

Show more replies
  • Liked by
Reply
Cancel