- Home /
How can I stop killing myself ?
Hello,
The following script kills the wrong character.
function OnTriggerEnter(collider : Collider)
{
if (collider.tag == "Default")
{
PhotonNetwork.Destroy(gameObject);
}
if (collider.tag == "Player")
{
PhotonNetwork.Destroy(gameObject);
var player : Player = collider.GetComponent(Player);
player.isDead = true;
}
}
How can I find a solution ?
Can you explain what you want the script to do? Because the lines 8 to 12 seem to destroy the player gameObject once the gameObject that the script is assigned to collides with the player. Check if the tags are right.
Does this kill you only when you hit another player, or every time you shoot?
If it's every shot, Landern is probably correct -- the game thinks you're shooting yourself in the back. Try spawning the bullet far about you to see if it still does it.
Nope, when I shoot on nothing, nothing appends. This occur only when I shoot a player tagged "Player".
I am trying to use Photon IDs to make different tags and see what appends.
Answer by Owen-Reynolds · Mar 12, 2013 at 04:33 PM
It sounds like a problem with uisng the networking code. Might have more luck asking specifically about photonNetwork.
The lines player : Player = collider.GetComponent(Player);
and player.isDead = true;
are killing the local copy of what got hit. Not sure how photon works, but you generally have to tell the owner of the object (server? that player?) that they have been killed. For example, PhotonNetwork.Destroy(gameObject);
is using the network to simul-kill all copies of the bullet.
Answer by Landern · Mar 12, 2013 at 01:47 PM
Chances are that you are killing yourself because as you use a weapon or fire a bullet, it is in fact either spawning within the collider of the player firing(or whatever) and the tag is Player, you need to either add a condition so that the players own projectiles/weapons do not case damage or that the local player's tag is renamed to say "LocalPlayer" instead of just player. This is only a guess though.
Answer by Gvrv · Mar 12, 2013 at 02:35 PM
The script I published it about when you shoot a bullet on objects (Default) and on various players on multiplayer (Player).
All the players have the same tag.
I checked to see if the laser doesn't shoot at the player himself, but not, otherwise the player will kill himself at every shot.
I also put the line "PhotonNetwork.Destroy(gameObject);" below "player.isDead = true;" but nothing change.
The player get killed everytime he shoot at another player.