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

character controller sample project

Discussion in 'Multiplayer' started by seanr, Jun 11, 2015.

  1. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Attached is a simple character controller sample project.

    This does not do animation.

    (There is a NetworkTransform bug with syncing rotation for CharacterControllers. This projects contains a workaround script that can be used until that is fixed).
     

    Attached Files:

    erebel55 likes this.
  2. erebel55

    erebel55

    Joined:
    Jun 14, 2014
    Posts:
    43
    Thank you for this, great for my needs :) Will basic animation be added?
     
  3. raja-bala

    raja-bala

    Joined:
    Jul 11, 2012
    Posts:
    29
    Hey Sean,

    I was trying to get two players' animated characters working over the network. I wasn't sure how to correctly sync their animations. The input layer uses `isLocalPlayer`, and I was hoping the `sync character controller` option would be enough. When i used that, it wouldn't move at all (not just a rotation issue).

    If you'd like to check it out, here's the github link and the SO question.
     
    metamorphist likes this.
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    In your ThirdPersonUserControl script, add:

    Code (CSharp):
    1.  
    2.         [Command]
    3.         void CmdMove(Vector3 move, bool crouch, bool jump)
    4.         {
    5.             RpcMove(move, crouch, jump);
    6.         }
    7.  
    8.         [ClientRpc]
    9.         void RpcMove(Vector3 move, bool crouch, bool jump)
    10.         {
    11.             if (isLocalPlayer)
    12.                 return;
    13.  
    14.             m_Move = move;
    15.             m_Crouch = crouch;
    16.             m_Jump = jump;
    17.             m_Character.Move(move, crouch, jump);
    18.         }
    Then call CmdMove for the local player, maybe in Update().
     
    raja-bala likes this.
  5. raja-bala

    raja-bala

    Joined:
    Jul 11, 2012
    Posts:
    29
    Thanks much @seanr!

    I removed the [SyncVar]'s in the script, in addition to that (since the RPC has the updated arguments at any point) and it works fine.

    Why didn't the earlier version work though? Since the movement variables were synchronized, it should have run the animation until each update, right?
    Also, when would I set `NetworkTransform.TransformSyncMode` to Sync Character Controller?
     
    metamorphist likes this.
  6. Meleong

    Meleong

    Joined:
    Sep 25, 2015
    Posts:
    1
    Thanks。
    非常感谢。
     
  7. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    I want to ask the same question as raja.bala:
    Why didn't the earlier version work though? Since the movement variables were synchronized, it should have run the animation until each update, right?
    Also, when would I set `NetworkTransform.TransformSyncMode` to Sync Character Controller?
     
  8. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Thanks Sean, it's great. I still want to ask: when should we use NetworkedTransform (sync Character Controler)?
     
  9. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    How can I get it to work? :(