Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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