Players dont move, but only when both in lobby

Options
I have two devices connecting to a lobby using PhotonEngine and im using the following code attached to two buttons to move the player left and right.
using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using Photon.Realtime;
    using UnityEngine.SceneManagement;
 
 
     
        public class movementScript : MonoBehaviourPun
        {
            Rigidbody2D rb;
 
           // float movement = 0;
            public float movementSpeed = 10;
            public float upForce = 290;
            public GameObject camPosition;
            Scene scene;     
 
            private bool directionLeft = false; //sole purpose for sprite movement
            private bool directionRight = false;
         
         
            // Start is called before the first frame update
            void Start()
            {
                rb = GetComponent<Rigidbody2D>();
                camPosition = GameObject.FindWithTag("MainCamera");
            }
 
           public void MoveRight()
            {
                directionRight = true;
 
                Vector3 characterScale = transform.localScale;
                float originalScale = -1f;
                characterScale.x = -originalScale;
                transform.localScale = characterScale;
 
                //move player at speed of movement
                Vector2 velocity = rb.velocity;
                velocity.x = (movementSpeed * Time.deltaTime);
                rb.velocity = velocity;
 
             
            }
 
            public void StopRight()
            {
                directionRight = false;
            }
 
            void ResetX()
            {
                Vector2 velocity = rb.velocity;
                velocity.x = 0f;
                rb.velocity = velocity;
            }
 
            public void MoveLeft()
            {
                directionLeft = true;
 
                Vector3 characterScale = transform.localScale;
                float originalScale = -1f;
                characterScale.x = originalScale;
                transform.localScale = characterScale;
 
                //move player at speed of movement
                Vector2 velocity = rb.velocity;
                 velocity.x = -(movementSpeed * Time.deltaTime);
                 rb.velocity = velocity;
 
             
            }
 
            public void StopLeft()
            {
                directionLeft = false;
            }
 
         
 
            // Update is called once per frame
            void Update()
            {
               if(!directionLeft && !directionRight)
                {
                    ResetX();
                }
           
            }
 
            public void TakeInputLeft()
            {
                if (photonView.IsMine)
                {
                    MoveLeft();
                }
            }
            public void TakeInputRight()
            {
                if (photonView.IsMine)
                {
                    MoveRight();
                }
            }
        }

When both players are in the game pressing either button does nothing. But when one player leaves the player left in the lobby has control as it should. Why does it only work when a player leaves?

JwqEV.png

I tried putting the touch control buttons within the player prefab so that each player spawns in with their own buttons but that did the same thing. Only works when the other player leaves.

Thanks

Comments

  • Tobias
    Options
    You want the client to react to local input. All the time. The trick to do in a multiplayer game is to apply this input only to one networked object (the player or character, etc). This will then update the other clients.

    We don't have the time currently to debug this but I would recommend reading and coding the Basics Tutorial once (more). It covers how input is applied, how characters get instantiated with the setup for networked gameplay.
    https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/

    Hope this helps.
  • ZakBrindle
    Options
    Thank you I will look into this and report back with progress!