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.
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);
}