I am moving a row of boxes across the screen and they are stuttering for some reason. They are UI images, on a default canvas. This is the only code running in the scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveMe : MonoBehaviour
{
void Update()
{
GetComponent<RectTransform>().position -= new Vector3(110f * Time.deltaTime, 0f, 0f);
}
}
It is being run on the parent object of all the boxes.
This is the stuttering I speak of: https://gfycat.com/ActiveQuestionableJaeger
Got any ideas as to what is causing it?
I would move one across the screen and check what values you’re getting in position. Also, I would look into better options for moving. This includes something like lerp or even a tween engine, depending on what you are moving the images for. Tween engines work really well for stuff like this.
Time.deltaTime is a value that will change and thus can create some different results.
@Afropenguinn
I’ve encountered some execution order issues with RectTransform in the past. I’ve solved it by distributing the position changing code over Update and LateUpdate.
It’s expected that Time.deltaTime changes. That’s normal. The frame rate varies, so the amount of time between frames changes. And Time.deltaTime gives you exactly the time elapsed from the previous frame so that you can update your object position accordingly.
How do you go about distributing it across both Update and LateUpdate? I’ve tried the code in my original post in LateUpdate, and it acted the same as far as I could tell.
@Afropenguinn
That was a while ago and I can’t recall exactly what the problem was for me. But it was related to RectTransform being updated with a delay with respect to Update. Have a look at this page, maybe you could try other functions instead of Update. Maybe OnPreRender?
I don’t have my computer with me, so I can’t try out you code and figure out what you problem is. Sorry, for not giving you a precise solution.