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.”
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