Search Unity

  1. We have added sub-forums for the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  3. Dismiss Notice

Help Wanted MLAPI First time using can't see other players moving around

Discussion in 'MLAPI' started by unkopath, May 15, 2021.

  1. unkopath

    unkopath

    Joined:
    Jun 23, 2018
    Posts:
    16
    Hi, I just saw a tutorial and trying to do my own script moving the player but ain't working, can someone tellme what i'm doing wrong? here is my script:


    Code (CSharp):
    1. using MLAPI;
    2. using MLAPI.Messaging;
    3. using MLAPI.NetworkVariable;
    4. using UnityEngine;
    5.  
    6. public class PlayerMovement : NetworkBehaviour
    7. {
    8.     private Rigidbody rigidBody;
    9.     public float speed = 6f;
    10.  
    11.     private void Awake()
    12.     {
    13.         rigidBody = GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     void FixedUpdate()
    17.     {
    18.         if (IsOwner)
    19.         {
    20.             MovePlayerServerRpc();
    21.         }    
    22.     }
    23.  
    24.     private void MovePlayer()
    25.     {
    26.         Vector3 m_Input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    27.         rigidBody.MovePosition(transform.position + m_Input * Time.deltaTime * speed);
    28.     }
    29.  
    30.     [ServerRpc]
    31.     private void MovePlayerServerRpc()
    32.     {
    33.         MovePlayerClientRpc();
    34.     }
    35.  
    36.     [ClientRpc]
    37.     private void MovePlayerClientRpc()
    38.     {
    39.         MovePlayer();
    40.     }
    41. }
    42.  
    43.  
     
  2. mitio31

    mitio31

    Joined:
    Apr 17, 2020
    Posts:
    3
    Hello there!
    First of all, using RPCs for player movement is not a good idea. I recommend you using Network Transform component on the player prefab. Network transform replicates network object's transform through the whole network. I suggest you reading the MLAPI documentation about the network components.
    I hope this will help you.
    If you have any further problems, please ask :)
     
unityunity