Posted March 27, 2024 by Bjornoid
Problem:
One thing that the game was missing after completing the revive system, was a spectator system for when players were not revived in a multiplayer game. Before, you would just be locked in to looking at your dead body on the ground and could only see things that came to you, but most games like this would normally give the ability to either spectate the other players in your match, from a first or third person view, or be able to fly around with simply a colliding camera. There was a little back and forth for which option I would end up choosing, I was unsuccessful at first when I tried to make the player spectate another player in third person attached to them. I was also struggling at first with getting free flying camera spectating, I could never get it to work in a way that would allow for the player to return to their body and get revived when the round ends and transitions to a new round.
Solution:
To solve the issues I was having with implementing the system, I had to do more research on how to dynamically un-possess and possess pawns from your player controller. I also had to do my own trial and error with how to get that correctly working in tangent with the revive system. Once I understood how to make the player un-possess the base player pawn, which then possesses a spectator pawn, I just had to make sure I reset some of the values that are set in the gamestate when a player downs. Lastly, I had to rework the spawning of the gamehud on begin play of the player class so that when respawning, it wouldn't create a new gamehud for the already alive players.