Smooth Movement issue

I created a new project with 3 spheres.
The code just moves one of the spheres back and forth between the other two.

I has a blurry/ ghost like movement. Sometimes it jerks.
I used Unity 2020.2.4f1.
My monitors are 144Hz. Unfortunately, I don’t a way to test otherwise.

Profiler is showing update is running at 4 to 1 ms (250 to 1000 FPS).

Any suggestions for troubleshooting or settings?

[SerializeField] float adjustableVar;
    public Transform LeftSphere, RightSphere, myT;
    public bool goLeft = false;
    bool isMoving = false;

    void Update()
    {
        if (LeftSphere == null) LeftSphere = GameObject.Find("/LeftSphere").transform;
        if (RightSphere == null) RightSphere = GameObject.Find("/RightSphere").transform;
        if (myT == null) myT = transform;

        if ((RightSphere.position - myT.position).magnitude <= 1) goLeft = true;       
        if ((LeftSphere.position - myT.position).magnitude <= 1) goLeft = false;

        // Looks terrible, even at 5f.
        //if (goLeft)
        //    myT.position = Vector3.MoveTowards(myT.position, LeftSphere.position, adjustableVar * Time.deltaTime); // Last var is max move
        //else
        //    myT.position = Vector3.MoveTowards(myT.position, RightSphere.position, adjustableVar * Time.deltaTime);

        // Performance is better, but still looks terrible.
        if (goLeft)
            StartCoroutine(moveToX(myT, LeftSphere.position, adjustableVar)); // Last variable is time duration
        else
            StartCoroutine(moveToX(myT, RightSphere.position, adjustableVar));
    }

    private void FixedUpdate()
    {
        // Same issue as update.
        //if (goLeft)
        //    myT.position = Vector3.MoveTowards(myT.position, LeftSphere.position, adjustableVar * Time.fixedDeltaTime);
        //else
        //    myT.position = Vector3.MoveTowards(myT.position, RightSphere.position, adjustableVar * Time.fixedDeltaTime);
    }

    IEnumerator moveToX(Transform fromPosition, Vector3 toPosition, float duration)
    {       
        if (isMoving) yield break; //exit if this is still running
        isMoving = true;
        float counter = 0;
        Vector3 startPos = fromPosition.position;
        while (counter < duration)
        {
            fromPosition.position = Vector3.Lerp(startPos, toPosition, counter / duration);
            counter += Time.deltaTime;
            yield return null;
        }
        isMoving = false;
    }

It may churk a bit in the editor because that is also updating the entire Unity editor UI… did you try it from an actual build on the target platform you intend to run it on?

I gave that a try. Made a build and closed out unity.
I still have the ghost effect.

I don’t see how performance is better with the overhead of a Coroutine

But anyways the problem here seems to be that you’re creating new Coroutines every single frame.

I’ve confirmed by adding Debug.Log("Activated") after if (isMoving) yield break; that the coroutine actives once each way and not every frame.

Sorry my bad, I didn’t look over it fully and realize you check inside the coroutine.

I appreciate any suggestions.

It just occurred to me that since vsync is on, I should not be seeing 250-1000 FPS in the profiler. It should be capped at 144.
Or am I misunderstanding?

@v4d3n did you maybe hide the CPU Usage Chart’s the “Others” category by toggling it of in the legend (i.e. the colored box to its left is black)?

Everything is selected including “others”
Why?

I tired turning off everything except VSync. Nothing displayed…

That was just an idea since that has tripped up others in the past and there were no screenshots to go by. Are you profiling playmode, Editor or a build and with which graphics API? Game view has its own VSync setting and VSync can behave different between build and editor (also if scene and game view are open)

Your “ghost effect” sounds like hardware. Specifically either monitor overshoot or slow response time. This does not refer to refresh rate, but instead the speed at which individual pixels can change colors. If this is the issue, it is unrelated to Unity.

See this video for an explanation. The relevant information starts at 3:52.

1 Like

Thanks everyone to who responded. Looks like Joe is correct, hardware.

I’ve been profiling Game view in the editor (if there’s another way to do it, I don’t know it). I didn’t know it had it’s own vSync settings and knowing that has helped with troubleshooting.
Graphics API - it’s set to auto? I think that means Direct X 11.
@Joe-Censored My monitor is one of the four on the splash screen lol. My response time is advertised as 1ms, so it must be overshooting (or my AOC isn’t actually 1ms).

Higher refresh rates (144Hz) look better than lower (60)

I discovered testufo.com thanks to your video. I do see a ghost effect there.

So the question becomes how to limit the noticeability of it. I’ll save that for a future thread.