New to multiplayer, I am using Unity 6 and using multiplayer tools 2nd player to test this.
I have tried using both Time.Deltatime and FixedDeltatime.
using System.Collections;
using Unity.Netcode;
using UnityEngine;
public class Test_Movement : NetworkBehaviour
{
public float movementSpeed = 10f;
private Vector2 movementDirection;
// Update is called once per frame
void Update()
{
if (!IsOwner) { return; }
input();
}
private void input()
{
float X = Input.GetAxis("Horizontal");
float Y = Input.GetAxis("Vertical");
MovementRPC(X, Y);
}
[Rpc(SendTo.Server)]
void MovementRPC(float X, float Y)
{
if (!IsServer) return;
movementDirection = new Vector2(X, Y).normalized;
transform.Translate(movementDirection * movementSpeed * Time.fixedDeltaTime);
}
}
public class TestGameManager : NetworkBehaviour
{
public List<Transform> spawnPoint;
public GameObject playerPrefab;
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
if (IsServer)
{
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
}
}
void OnClientConnected(ulong clientId)
{
var spawnedPlayer = Instantiate(playerPrefab, spawnPoint[((int)clientId)].position, Quaternion.identity);
spawnedPlayer.GetComponent<NetworkObject>().SpawnWithOwnership(clientId);
}
}