2

I have a problem with movement 2 or more people in only one team. In one team it runs as it should, everyone controls himself, but in the other team if more than 1 player joins, so 1 controls the other.

I have 4 player types (2 for one team and 2 for the other), so 4 prefabs that I call when I need them, when I start the room.

void CreateController()
{
.
.
.
    if (attackTeam == true && deffTeam == false && attAR_ == true)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Att_player_AR"), spawnpointA.position, spawnpointA.rotation, 0, new object[] { PV.ViewID });

    if (attackTeam == true && deffTeam == false && attSniper_ == true)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Att_player_Sniper"), spawnpointC.position, spawnpointC.rotation, 0, new object[] { PV.ViewID });

    if (deffTeam == true && attackTeam == false && defAR_ == true)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Def_player_AR"), spawnpointD.position, spawnpointD.rotation, 0, new object[] { PV.ViewID });

    if (deffTeam == true && attackTeam == false && defSniper_ == true)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Def_player_Sniper"), spawnpointB.position, spawnpointB.rotation, 0, new object[] { PV.ViewID });
.
.
.
}

And everywhere there should be a check if photonView isMine

PhotonView PV;
.
.
.

void Awake()
{
    PV = GetComponent<PhotonView>();
}

void Start()
{
    if (PV.IsMine)
    {
        CreateController();
    }
}

And in those 4 prefabs I have PhotonView for all of them and in the script I check if photonView Is Mine too

protected virtual void Update()
{
    if (!PV.IsMine)
    {
        return;
    }

    if (isDead == false && timerOut == false)
    {
        if (m_characterController && gamePaused == false)
        {
            // Check if Grounded,Wall etc
            CheckIfGrounded();
            CheckIfWall();

            // Apply Smoothing
            SmoothInput();
            SmoothSpeed();
            SmoothDir();

            if (experimental)
                SmoothInputMagnitude();

            // Calculate Movement
            CalculateMovementDirection();
            CalculateSpeed();
            CalculateFinalMovement();

            // Handle Player Movement, Gravity, Jump, Crouch etc.
            HandleCrouch();
            HandleHeadBob();
            HandleRunFOV();
            HandleCameraSway();
            HandleLanding();

            ApplyMovement();
.
.
.       }
    }
}

Everything should be correct, all prefab scripts should be exactly the same in terms of movement, but I really don't know where the mistake is. I've checked everything like a million times and haven't found anything.

Although I don't know if anyone will figure it out, at least from what I've shown, but any comments and advice would be appreciated.

Gan
  • 53
  • 4

2 Answers2

1

I solved the problem, the problem was that I didn't destroy the cameras of the others

        if (PV.IsMine)
        {
            EquipItem(0);
        }
        else
        {
            Destroy(GetComponentInChildren<Camera>().gameObject);
            Destroy(rb);
        }
Gan
  • 53
  • 4
0

Make sure you set all variables attackTeam, deffTeam, attAR_ etc. correctly (you don't show where you assign them). I also suggest more clear syntax in CreateController().

Supposing that when you have bool attackTeam set to true, there is no need to check for deffTeam to be false. I would write something like this:

if (attackTeam) 
{
    if (attAR_)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Att_player_AR"), spawnpointA.position, spawnpointA.rotation, 0, new object[] { PV.ViewID });
    else
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Att_player_Sniper"), spawnpointC.position, spawnpointC.rotation, 0, new object[] { PV.ViewID });
}
else
{
    if (defAR_)
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Def_player_AR"), spawnpointD.position, spawnpointD.rotation, 0, new object[] { PV.ViewID });
    else
        controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Def_player_Sniper"), spawnpointB.position, spawnpointB.rotation, 0, new object[] { PV.ViewID });
}
AdamDevv
  • 27
  • 4
  • I don't think there could be a mistake. If only for the reason that all prefabs seem to "spawn" me well. Here are 2 videos where you can see the problem I described. https://www.youtube.com/watch?v=mK9j675bRyM https://youtu.be/Ddjeoj6rFpg And thanks for suggesting cleaner code :D – Gan Nov 30 '21 at 12:20