Looping background for client in netcode for gameobject

From the host’s perspective, the looping background looks smooth, but not from the client’s perspective. When the object tries to return to its default position, it seems like it is moving backward, not like “teleporting.”
2025-01-1607-34-16-Trim-ezgif.com-video-to-gif-converter

Here is the script for the background.

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class BackgroundLooping: NetworkBehaviour
{
    [SerializeField] private float speed;
    [SerializeField] private Vector2 moveDir;
    [SerializeField] private float maxMove;

    private float speedMax = 5f;
    private float speedMin = 0f;
    private float currentSpeed;
    private float accelerationSpeed = 10f;

    private Vector3 startPos;

    private void Start()
    {
        startPos = transform.position;
    }

    private void Update()
    {
        if (!IsOwner) return;

        if (GameManager_RankedMode.Instance.IsPlayerFull())
        {
            if (speed < speedMax)
            {
                currentSpeed = Mathf.Clamp(currentSpeed + accelerationSpeed * Time.deltaTime, speedMin, speedMax);
                speed = currentSpeed;
            }

            RequestMoveServerRpc(moveDir * speed * Time.deltaTime);
        }
    }

    [ServerRpc(RequireOwnership = false)]
    private void RequestMoveServerRpc(Vector2 moveAmount)
    {
        HandleMoving(moveAmount);
    }

    private void HandleMoving(Vector2 moveAmount)
    {
        transform.Translate(moveAmount);

        if (Vector3.Distance(transform.position, startPos) >= maxMove)
        {
            transform.position = startPos;
        }
    }
}

*Sorry if there is already an answer to this question but before I posted this I didn’t find any answer to this problem.

Thank you in advance

If you’re just using a straight road, don’t even bother moving the gameobject at all. Instead, set the texture to tile and then script it so that the texture’s Y offset changes.

1 Like

Ahh i see… I’ll try that method. Thank you so much for the advice!