Search Unity

Resolved Starter Assets Third Person Controller and Netcode for GameObjects

Discussion in 'Multiplayer' started by Hotshot10101, Nov 8, 2022.

  1. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I wasn't sure where to post this. I could have put it in Cinemachine or Input System or here and figured this was most appropriate.

    I am making a multiplayer game using NGO and the Starter Assets Third Person Controller.

    I am using Unity 2021.3 and the latest release versions of NGO. No beta stuff.

    I put the NetworkObject on the parent of the "system" that the 3rd person controller prefab includes. The children include a cinemachine system and the whole thing uses the "new" unity input system.

    When I start the Mac app I built and start the Host and walk around everything works as it should. I can walk around and the cinemachine camera follows like it should.

    I am using the github ClientNetworkTransform because I am fine with client auth for movement.

    I also created my own OwnerNetworkAnimation so I could get the client auth for animation according to the documentation on the Unity website.

    When I then start the editor and connect as a client, the cinemachine camera in the app that is running looks like it switches to the client that just spawned in. If I shutdown the client then cinemachine goes back to the host avitar.

    Along with that the Host player that spawns in to the game running in the editor spawns in the same spot as the client. The initial position isn't updated. As soon as I move the player in the Host app, the player does move in the editor app.

    When I try to move the player in the editor (client), the animation plays on the HOST player avatar. It doesn't move, but the animation plays. This seems to tell me that the input manager is sending stuff to the wrong avatar or the wront avatar is listening or something like that.

    As a second issue, even though I have the client auth component, when I try to move in the client the animation plays, but it doesn't move.

    A third issue is that animations are not syncing at all.

    I could really use some help to get this to work.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,899
  3. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Thank you! I will give this a try.
     
  4. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I am having trouble opening your project. I get the following error:

    upload_2022-11-9_7-44-53.png

    Not sure why you have a direct reference to your hard drive in the packages file.

    I also tried just making my own project and copying just the Third Person folder to it and it gives errors about duplicate methods in the thirdpersoncontroller script because i also have the third person asset in my project.

    Without the unity assets in my project, however, I get errors that there are missing scripts.

    I really appreciate your helping, but would like some instruction on how to use what you have created....
     
  5. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hey @Hotshot10101 , you can fix the reference to the package by opening your project's folder and going into Packages > manifest.json . There you should be able to specify the version of @CodeSmile 's package instead of a local path.

    I'm not a user of such package, but from what I see here one of the live versions should be 0.1.0, so you should be able to specify

    Code (CSharp):
    1. "com.codesmile.core": "0.1.0",
    in your manifest file.

    Does this help?
     
  6. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    upload_2022-11-9_8-21-50.png
     

    Attached Files:

  7. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @Hotshot10101 I found CodeSmile's package on its public github, it's here. You should be able to reference the latest commit ( 5ec2764d89b8757c6ad20e1ec7bbf4083f5ea561 ) from the develop branch of its repo by adding to your manifest:

    Code (CSharp):
    1. "com.codesmile.core": "https://github.com/CodeSmile-0000011110110111/CodeSmile-Package.git#5ec2764d89b8757c6ad20e1ec7bbf4083f5ea561",
     
  8. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
  9. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hey @Hotshot10101 , I have an update for you: maybe you're experiencing a similar issue to the one mentioned in this thread . Maybe some of the concepts explained there would apply to you?

    I just modified the ThirdPersonController that comes with the standard assets to make it usable in a multiplayer environment. Basically all I did was:

    1. Make it a NetworkBehaviour
    2. Add if (!IsOwner) { return; } at the beginning of the Update() to ensure only the inputs from the local owner are sent

     
  10. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Your timing is great. I was just thinking about this last night when I was going over a tutorial video. I suspect you are right.

    Thanks for confirming that is probably it!
     
    RikuTheFuffs-U likes this.
  11. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    How did you deal with the fact that the NetworkBehaviour requires a NetworkObject on the same GameObject?

    The reason this is an issue is because in order to have a single GameObject to put on the NetworkManager, I created an empty GameObject and put the entire Third Person stuff under that. This includes the PlayerAmature, PlayerFollowCamera, etc.

    Without all those things it doesn't seem to work.

    I had to put the NetworkObject on that parent game object and then drag that onto the NetworkManager as the player spawn.

    That means I can't put the NetworkObject onto the PlayerAmature and it keeps complaining that a NetworkBehaviour needs a NetworkObject with it.
     
  12. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    The host side does seem to work now including the animations, but the camera isn't following and the client side isn't working, so still looking into those.
     
  13. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    I didn't: i'm using the PlayerArmature as the parent object, so all the scripts are on it (including NetworkObject). Is it something you could do too?

    You should set the target of the camera as the local player, and ensure other players don't have a camera at all (I.E: by removing it from the prefab and instantiating + assigning it in the OnNetworkSpawn of a NetworkBehaviour of the Player, or by keeping it disabled and enabling it for the local player only using OnNetworkSpawn)
     
  14. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I ended up doing something like this.

    I made the PlayerArmature the player object that will get instantiated and then put a single copy of the rest of the stuff in the scene.

    I then had to modify several of the scripts to use the IsOwner to only do a lot of the functionality in that case.

    This seems to work.

    thanks for all the help and tips.
     
    RikuTheFuffs-U likes this.
  15. al33f

    al33f

    Joined:
    Aug 2, 2017
    Posts:
    9
    That's definitely not enough. The host will work just fine that way but the client won't be able to move (using NetworkTransform and not ClientNetworkTransform). I understand the movement has to happen on the server through a serverRPC but it's just confusing enough that I can't figure it out on my own. I'd really appreciate your help.
    EDIT: I was so close but couldn't figure out what I was doing wrong. Then I found this video and everything I needed was in there:
     
    Last edited: Jan 3, 2023
    Doraemon231, shaba9 and Narkdagas like this.
  16. Doraemon231

    Doraemon231

    Joined:
    Dec 18, 2018
    Posts:
    22
    Thank You!
     
  17. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    The video seems to be blocked. Is there a way for you to make the link visible?
     
  18. leeprobert

    leeprobert

    Joined:
    Feb 12, 2015
    Posts:
    49
    The video is great but for some reason the input animation mapping is messed up when you go backwards.
     
  19. leeprobert

    leeprobert

    Joined:
    Feb 12, 2015
    Posts:
    49
    There's a slight difference with the Cinemachine camera that you need to be aware of. In the video he sets the camera to follow the transform of the GameObject. The starter asset uses a child transform for the follow. It's called `PlayerCameraRoot` and you set this in the inspector on the PlayerController as the `Cinemachine camera target`. To set this programmatically, replace the code you will have copied from the video above with this:
    ```
    public override void OnNetworkSpawn()
    {
    base.OnNetworkSpawn();​

    if(IsClient && IsOwner){
    _playerInput = GetComponent<PlayerInput>();
    _playerInput.enabled = true;
    // _cinemachineVirtualCamera.Follow = transform;
    if(CinemachineCameraTarget != null){
    _cinemachineVirtualCamera.Follow = CinemachineCameraTarget.transform;​
    }else{
    _cinemachineVirtualCamera.Follow = transform;​
    }​
    }​
    }
    ```
     
    Hotshot10101 likes this.
  20. Cula_Hisoka

    Cula_Hisoka

    Joined:
    Aug 19, 2023
    Posts:
    1
    how can i turn it to NetworkBehaviour, actually my code doesn't work with unity.netcode;
    I think maybe it in packages and netcode in other folder.
    upload_2024-3-7_9-28-49.png

    help me please