0
\$\begingroup\$

I have a player controller attached to the Player prefab - along with the NGO components

Network Object Client Network Transform Network Animator

In the Network Manager I have the Player prefab added so that the host & clients will spawn when joining.

The issue I have is that the user input from client & host is controlling both prefabs on screen at the same time.

On the player controller script I have the line if (!IsOwner) return; at the start of the Update() before any movement is called

The Player Prefab is setup as follows:

  • Player (Has the Network Object & Client Network Transform components)Parent Obj

  • Controller (Has the PlayerController script attached to it)

  • Model (Has the Owner Network Animator component with the Animator applied)

Any help much appreciated.

PlayerController update():

void Update()
    {
        if(!IsOwner) return;
     
        if (!rigidbody || !animator) return;
 
        currentVelocity = rigidbody.velocity;
 
        GetAxisHistory();
 
        GetTargetHeading();
 
        GetLocomotionState();
 
        GetTurnSpeed();
 
        if (currentAnimationStates.HasFlag(AnimationPlayerStates.Pivoting))
        {
            SetTurnParams();
        }
        else if (TurnTriggerIsSet())
        {
            SetVelocityToCurrent();
        }
        else
        {
            TurnCheck();
 
            SetLocomotionVelocity();
        }
    }

enter image description here

enter image description here

I am using the New Input System

See the attached video for the issue

https://youtu.be/udOMW0Fbu14

\$\endgroup\$
3
  • \$\begingroup\$ Can you post your PlayerController code? And maybe screenshot the inspector for the GameObject? \$\endgroup\$
    – John B
    Nov 2, 2022 at 14:34
  • \$\begingroup\$ @JohnB thanks for your reply - I have added the info to the post now \$\endgroup\$ Nov 2, 2022 at 15:25
  • \$\begingroup\$ Where is the PlayerController script? What GameObject is it connected to? \$\endgroup\$
    – John B
    Nov 2, 2022 at 16:16

2 Answers 2

0
\$\begingroup\$

I'm wondering if the IsOwner check is not working properly because it looks like you might have the PlayerController script attached to something nested under the NetworkObject.

Try moving it up to the Player GameObject.

\$\endgroup\$
2
  • \$\begingroup\$ Same outcome. So I have this solution working in another smaller project using public override void OnNetworkSpawn() { if (!IsLocalPlayer) enabled = false; } Turning off the player controller script for the player that is not local. This works fine in the prototype project but I cant get it to work the same way in my main project The script is disabling as expected but the 2 players are still being controlled on both the Host & Client from both inputs. Could this be an issue with the new input system? Do I need to have a control scheme for Player1 & Player2? \$\endgroup\$ Nov 4, 2022 at 8:23
  • \$\begingroup\$ I don't think that the new Input System should matter in this case... There is probably one more place where the logic is disconnected from what it should be. I would try bringing your small test example over into your game and getting that working with the new Input System... I'm guessing it will work just fine. As long as you're checking for IsLocalPlayer or IsOwner (whichever is needed) before applying your inputs, you should be good. \$\endgroup\$
    – John B
    Nov 7, 2022 at 14:45
0
\$\begingroup\$

So it was because I was using 2 instances on the same machine - the input was being read by both. I was able to get the outcome when I played a host & client across 2 different machines using gamepads. Each gamepad controlled their own player

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .