Question by
hans_ruebe · May 01, 2021 at 01:00 PM ·
scripting problem
[Command] not called on the server
Hello every one I am just setting up a Networked Game in mirror but the [Command] CmdMove() is not called on the server... I have tried a lot of fixes... do you have any Ideas
public class PlayerMovement : NetworkBehaviour
{
[SerializeField]
private float movementSpeed = 5;
private Vector3 horizontal, vertical;
private void Start()
{
horizontal = new Vector3(1, 0, 1);
horizontal = Vector3.Normalize(horizontal);
vertical = Quaternion.Euler(new Vector3(0, 90, 0)) * horizontal;
}
#region Server
[Command]
private void CmdMove()
{
Vector3 verticalMovement = vertical * movementSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
Vector3 horizontalMovement = horizontal * movementSpeed * Time.deltaTime * Input.GetAxis("Vertical");
Vector3 heading = Vector3.Normalize(verticalMovement + horizontalMovement);
transform.forward = heading;
transform.position += verticalMovement;
transform.position += horizontalMovement;
}
#endregion
#region Client - Only runs on clients
//Client callback makes sure that its not on Server and Client
//So functions with client callback are only run on all clients
[ClientCallback]
private void Update()
{
//If we don't own the Object try again...
if (!hasAuthority) { return; }
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
{
Debug.Log("I want to move");
CmdMove();
}
}
#endregion
Comment
Your answer