- Home /
Question by
GlorifiedPig · Oct 17, 2018 at 11:55 AM ·
unity 5physicsnetworkingquaternionraycasts
Death handling peculiarly
Hey there, so I have a bomb with an explosion script that's networked, and when the bomb explodes, it sends out a Physics.OverlapSphere and if it detects a player, it kills the player. There are many issues with my killing system, and I am struggling to understand why. These issues include but are not limited to;
Deaths not always networking
Statistic counters either not going up at all, or sometimes going up too many times
Here's my code for the explosion:
Collider[] oSphereHits;
oSphereHits = Physics.OverlapSphere( transform.position, explosionBlockDistance * 3 + 2, ~15 );
List<GameObject> killedPlayers = new List<GameObject>();
for (int i = 0; i < oSphereHits.Length; i++)
{
Collider col = oSphereHits[i];
RaycastHit hit;
if( Physics.Raycast( transform.position, col.transform.position - transform.position, out hit, explosionBlockDistance * 3, ~15 ) ) {
if( hit.transform.gameObject.layer == 9 ) {
if( !killedPlayers.Contains( hit.transform.gameObject ) ) {
killedPlayers.Add( hit.transform.gameObject );
}
}
}
}
if( killedPlayers.Count > 0 ) {
Debug.Log( killedPlayers.Count );
foreach( GameObject killedPlayer in killedPlayers ) {
killedPlayer.GetComponent<LocalPlayerSetup>().KillPlayer( placedPlayer, killedPlayers.Count );
}
}
placedPlayer.GetComponent<LocalPlayerSetup>().currentBombs -= 1;
CmdDestroyBomb();
Here's my code for killing the player:
public void KillPlayer( GameObject killer, int killCount ) {
playerKiller = killer;
transform.rotation = Quaternion.Euler( 0, 0, 0 );
transform.eulerAngles = new Vector3( 0, 0, 0 );
transform.localEulerAngles = new Vector3( 0, 0, 0 );
if( isLocalPlayer ) {
StatCallbacks.SetStatistic( "STAT_TOTAL_DEATHS", StatCallbacks.GetStatistic( "STAT_TOTAL_DEATHS" ) + 1 );
}
if( killer != this.gameObject ) {
killer.GetComponent<LocalPlayerSetup>().totalKills++;
}
if( killer == this.gameObject && isLocalPlayer ) {
StatCallbacks.UnlockAchievement( "ACH_SUICIDE" );
if( killCount > 1 ) {
StatCallbacks.UnlockAchievement( "ACH_KAMIKAZE" );
}
}
isSpectating = true;
}
Comment
Your answer
Follow this Question
Related Questions
Car Syncing Problems with Photon 0 Answers
[UNET]Spring Joints and Networking. possibly a bug? 0 Answers
SyncListStruct Unity Error 0 Answers