Re-spawn all players after kill



  • Is it possible to have both players re-spawn back to their spawn point after one player dies? BTW, I have the game set to 2 player mode.



  • Of course. You could modify the RpcRespawn method in the Player script for this, or write a new Rpc (e.g. in the GameManager script) that all player's listen to.



  • Thanks for the reply, I’ll give it a try. I will report back if I run into any issues.



  • So I’m looking at the player script, is line 556 the line I would modify?



  • Line 556 in which script, Photon or UNET? Please post the line with code tags, you might have modified the script anyway.

    Your request is not a one-liner modification in the RpcRespawn method though. You have to understand how RPCs work - the method is invoked on all clients, but only for that specific player object. So if you kill the enemy player, the RpcRespawn method is not called for your own player object - only for the enemy player.

    As I wrote, there are several approaches to this. You first have to get familiar with how networking code works, before modifiying the source.

    • You could write your own RPC which is called for all clients (e.g. in the GameManager)
    • You could use the RpcRespawn method, which forwards the action to all players
    • You could use the RpcRespawn method for the enemy player, and send an RPC to your local player (GameManager.GetInstance().localPlayer)


  • Sorry, forgot to mention. I'm using photon, I was looking at line 556 on the player script.
    transform.position = GameManager.GetInstance().GetSpawnPosition(GetView().GetTeam());

    p.s this is my first time working with photon or anything multiplayer related. so you would recommend modifying the game manager script instead?



  • I would recommend learning the basics first, since multiplayer is complex in general, and even more if you are not familiar with Photon.

    https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent

    A separate or modified call to the GameManager script would be more easy, yes. Have a look at the TakeDamage method in the Player script. It is executed on the master client only - there is a check that detects a kill, and if IsGameOver() is true, it sends the "RpcGameOver" RPC to all clients (also Player script, it just calls a GameManager method).

    Your request is basically the same but without the IsGameOver() check, but on every kill.



  • @Baroni thanks for the info, I will look into rpcspawning.


Log in to reply