Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question How do i move the client while using server RPC

Discussion in 'Multiplayer' started by Apood61, Jan 27, 2023.

  1. Apood61

    Apood61

    Joined:
    Aug 8, 2021
    Posts:
    20
    So, I'm using a server RPC to move the player it works but it doesn't work with client, so I don't know what is the problem this the code:
    Code (CSharp):
    1. [ServerRpc]
    2.    private void MovementServerRpc()
    3.    {
    4.         DefaultMovement();
    5.    }
    and the default movement code :
    Code (CSharp):
    1. private void DefaultMovement()
    2.     {
    3.         if (!IsOwner) return;
    4.      
    5.         if (_controller.isGrounded)
    6.         {
    7.             SetSpeed();
    8.  
    9.             Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;
    10.  
    11.             _moveDirection.x = input.x * _speed;
    12.             _moveDirection.z = input.y * _speed;
    13.             _moveDirection.y = -settings.antiBump;
    14.  
    15.             _moveDirection = transform.TransformDirection(_moveDirection);
    16.  
    17.             if (Input.GetKey(KeyCode.Space))
    18.             {
    19.                 Jump();
    20.             }
    21.         }
    22.         else
    23.         {
    24.             _moveDirection.y -= settings.gravity * Time.deltaTime;
    25.         }
    26.     }
     
    Last edited: Jan 27, 2023
  2. Apood61

    Apood61

    Joined:
    Aug 8, 2021
    Posts:
    20
    also sometimes it says server RPC Requires owner ship
     
  3. MrBigly

    MrBigly

    Joined:
    Oct 30, 2017
    Posts:
    221
    Do you have a CharacterController attached to the immovable player? If so, try disabling it to see if it is the problem.
     
  4. Apood61

    Apood61

    Joined:
    Aug 8, 2021
    Posts:
    20
    acttualy no the character or the host moves but the client or the person who connected will not move for some reason or another