Bug Fixing and Game Over
Game Over Logic (GameManager.cs): Added a CheckGameOver() method that listens for player-death events and displays the endgame UI when one team is eliminated.
Team Assignment Storage (ChooseTeam.cs): Introduced AssignTeamToGameManager(int teamId) to pass the local player’s team selection into GameManager for later game-over evaluation.
Gun Pickup Mechanic (GunPickup.cs): Created an OnTriggerEnter(Collider other) handler that detects the player collider, shows a “Press E to Pickup” GUI label, and assigns the weapon prefab to the player.
Health Notification (Health.cs): Implemented health tracking with a currentHealth field; when it reaches zero, the script calls GameManager.Instance.PlayerDied(playerId).
Mouse-Look Ownership Fix (MouseLook.cs): Wrapped all Input.GetAxis calls inside if(photonView.IsMine) so only the local player’s camera responds to mouse movement.
Spawn Script Separation (SpawnIn.cs): Extracted the waiting-room spawn logic into its own SpawnIn.cs, instantiating the chosen character prefab at the correct spawn point for each player.
Weapon Shooting Logic (WeaponShooting.cs): Developed a Fire() method that checks ammo, applies recoil, and uses photonView.RPC("RPC_Fire", RpcTarget.All, hitInfo) to deal damage across the network.
Team-Assignment Bug Fix (ChooseTeam.cs): Tightened ID validation in the quick-join path to ensure players never end up on the wrong team.
// GameManager.cs – game-over check
public void CheckGameOver()
{
if (teams[0].PlayersAlive == 0 || teams[1].PlayersAlive == 0)
{
ShowGameOverScreen();
}
}
// ChooseTeam.cs – passing team to GameManager
public void AssignTeamToGameManager(int teamId)
{
GameManager.Instance.AssignTeam(PhotonNetwork.LocalPlayer.ActorNumber, teamId);
}
// GunPickup.cs – trigger-based pickup
private void OnTriggerEnter(Collider other)
{
if (!other.CompareTag("Player")) return;
promptText.text = "Press E to Pickup";
if (Input.GetKeyDown(KeyCode.E))
{
other.GetComponent<PlayerInventory>().AddWeapon(weaponPrefab);
Destroy(gameObject);
}
}
// MouseLook.cs – ownership guard
void Update()
{
if (!photonView.IsMine) return;
float yaw = Input.GetAxis("Mouse X") * sensitivity;
float pitch = Input.GetAxis("Mouse Y") * sensitivity;
transform.Rotate(-pitch, yaw, 0);
}
Related games implementation features and practices
- Overwatch orders spawn slots by player ID and monitors alive counts to trigger end-of-round screens.
- Call of Duty uses trigger-based pickups (e.g., weapons, ammo) with on-screen prompts to guide players.
- Apex Legends enforces client-side ownership checks on camera and input components to prevent desync.
Analysis of implementation
- Metrics Tracked:
- - Number of pickup triggers fired vs. weapons actually added.
- - Health-script calls to
PlayerDied()and their timestamps. - - MouseLook input skips on non-local clients (no stray rotations).
Results and Feedback on the implementation
- Stable Endgame: Game-over UI appears reliably when a team reaches zero players, with no mid-round false positives.
- Reliable Pickups: Gun pickups work most of the time in alpha tests, a rare collider error where the trigger still caused collision.
- Accurate Death Tracking: Health script correctly fires
PlayerDied()every time health hits zero, enabling consistent scorekeeping. - Smooth Input Ownership: No camera or control drift observed on remote clients after ownership guard was added.
- Next Steps: Implement audio cues for pickups, add cooldown visuals before next spawn.
References
. Photon forum - Assign Team: https://forum.photonengine.com/discussion/12360/check-and-assign-team
. Photon PUN 2 Documentation – PhotonView Ownership: https://doc.photonengine.com/pun/current/gameplay/ownershipandcontrol
Comments
Post a Comment