Other clients don't always take damage when hit

Hi there.

I'm currently creating a FPS game by the use of the PUN cloud service. But as of right now, I've encountered a problem with my health and damage system, which I simply can't figure out. The issue does not seem consistent to me, so I'm having a really hard time debugging and after having tried for a couple of days, I'm now out of ideas for possible solutions.

I'll try my best with an explanation of my setup of health and damage followed by the issue i'm facing and lastly what I've done in pursuit of solving it:

Setup of health and damage:
- I use a RPC to call my shoot method, so all players can see the shot. This is a raycastHit and calls a method on the player it collided with called "AdjustCurrentHealth".
- The AdjustCurrentHealth subtracts the damage for the player and sets the ID of the lastAttacker.
- In my update method, I check if health is equal to 0. If so, call the method "Killed".
- In my Killed method i move the gameObject (faking death without destroying - had some issues with my scoreboard when destroying so that's why they're just being moved). I disable my Shooting script. I also start a delay which calls Respawn method after 3 seconds. Lastly it updates the Death score and calls a method to increase kill score for the lastAttacker ID.
- The Respawn method resets health = maxHealth, moves the player to one of 4 fixed locations and also re-enables the Shooting script.

The issue that sometimes occurs (not always!), is that player A can shoot player B with more than 30+ shots and player B does not lose any health.

player B has 100 life and takes 10 damage pr. hit. If I hit another player, a blood particle is shown if not another particle system is shown. So the client can see that he hits another player a lot of times, but the player being hit does not take any damage.
When it happens, the player being hit doesn't take any damage at all, so it is not like he registers half of the hits and the other half is lost. None of them applies damage to him and then I sometimes I can just wait a couple of seconds, shoot him again and everything works fine until next time it happens.

What I've tried:
- At first I tried to make my AdjustHealth method into a RPC, to ensure that all players would know that this guy has taken damage. No luck - and damage started being multiplied per instance in the game, since it ran the method once for all other clients.
- Then I tried synchronizing my health in the same fashion I do it with the players' positions and rotations as well as axis input to the Animator through the OnPhotonSerializeView(). No luck.
- I have now made my health a customProperty of the PhotonNetwork.player, like I've also made "Kills" and "Deaths" custom properties. This has made all the clients synchronize how much health each player has when the issue occurs. Before this there was irregularities, so eg. Player A thought Player B had 20 HP, but Player B himself thought he had 40.

So now the health is in sync on all clients, but it doesn't always run the AdjustHealth method even though I see the blood, which means I must have hit that guy!

my 2 cent
I was thinking that it could be because of the position.Lerp I use to smooth the movement of the players. So Player A shoots player B, but player B is already in another position on his own client. However, player A is still just viewing player B's lerp to that position and shoots at that.
- This came to me because it seemed like the issue would occur more frequently if both player A and B was running around while being shot as opposed to shooting player B where he just spawned. But I can't say with certainty.

relevant scripts:
PlayerHealth.cs: http://pastebin.com/AHh1KmYG
Shooting.cs: http://pastebin.com/FrbP1vrf
(Sync: http://pastebin.com/DUpjggnS )

Any help, thoughts or ideas are most appreciated!
Thank you for your time

Best regards

Oh yeah, I totally forgot:

Yesterday when I had rewritten my PlayerHealth.cs and was testing the new version, I did not use any custom properties at all, and it seemed like everything worked like a charm. But this was even way before I made currentHealth into a custom property of the PhotonPlayer, so I can't see any direct link between these things.

Maybe the PhotonHashTable is set to destroy my exact setup of player health? :D
I don't know, I just thought it was worth mentioning.


  • So you found the little trick our Hashtable does?!

    Despite the good description, I would have to debug or "log" stuff in your project to find out what goes wrong. It could fail on so many levels.
    By debug log I would make sure the following pieces actually work.
    a) The RPC for the shot. Have some output on the receiving end to make sure it's called at all and correctly.
    b) The Adjust method. Make sure it's called. If it's not: Why? Maybe it's c).
    c) The raycast. Maybe what you send might be misunderstood on the receiving end. A character could move while someone sends a shot. While the raycast succeeds on the origin machine it can fail on another. You could send "i hit player X" with the next shot, if all else fails.

    If you re-checked all, we would need a minimal reproduction project. Load it up somewhere and send me the link to: [email protected]. Maybe we can take a look and find something.