Below is the code for movement of player object and it works perfectly fine. But in the TellClientsToMoveClientRpc
why are we doing transform.position
as it refers to the the current gameobject but not every object moves, only the one which called the above Rpc moves which is desirable. But why all other gameobject do not move ?
using UnityEngine;
namespace HelloWorld
{
public class HelloWorldPlayer : NetworkBehaviour
{
private const float speed = 20f;
private void Update()
{
if (!IsOwner)
return;
PlayerMove();
}
void PlayerMove()
{
Vector3 velocity = new(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
if(velocity.sqrMagnitude >= 1)
{
TellServerToMoveClientServerRpc(velocity, NetworkManager.Singleton.LocalClientId);
}
}
[ServerRpc]
void TellServerToMoveClientServerRpc(Vector3 velocity, ulong clientId)
{
TellClientsToMoveClientRpc(velocity, clientId);
}
[ClientRpc]
void TellClientsToMoveClientRpc(Vector3 velocity, ulong clientId)
{
transform.position += speed * Time.deltaTime * velocity;
}
}
}```