Player collision detect to start an event

Hello friends.
I hope you have all had a nice week.

I am trying to implement a feature in my game in which when a character dies, his spawn grouping is changed to 99, and thus spawns at a different set of spawns.
This works so far, but it activates from when the characters respawns, the grouping is changed.
This means if he is killed by another player, his grouping changes to 99, if he stands in fire or falldamage ect its 99.

I am trying to figure out a way so if my character dies from being shot, it can change to 99, but drowning or falldamage ect could be something else.
My idea for this was to create a box under the water that if you touch, your grouping changes to 50, but I am unsure how to write one of these into my script.

I will attach a picture -
When my character equips the assault rifle, all those events in the right side work, apart from the respawn event in red seems to happen twice, he respawns at grouping 99 once he equips the rifle, but a few seconds after respawning once he leaves that area it spawns him again.
Equiping the gun does change the grouping, and respawns the character in the correct place, but is it possible to have this functionality on an item or hitbox that the character doesn't need to pick up and equip? can I somehow add an OnCollideEvent() ?

Thanks for all the help so far.
 

Attachments

  • ideas.png
    ideas.png
    73.1 KB · Views: 8
Last edited:
Pretty much I am trying to find out how to change the grouping depending on whether the character dies in a fire, or is shot by a player, or falls in the water.
At the moment, any kind of death leads to grouping 99.
 
The OnDeath event includes the object that caused the character's death (if it is given). so you could use that to determine what grouping to assign.
 
The OnDeath event includes the object that caused the character's death (if it is given). so you could use that to determine what grouping to assign.
Thanks for the quick reply!
I really really appreciate it :)


I have it working so that when the player is hit by another player, it prints the message "aaaaah" in the console 5 times.
I am just wondering if I could be pointed in the right direction of changing the grouping through my script of the player instead of that "aaaaah" line.

(this script is on my main player object)

Again, thanks for all the help this is the best asset I have ever used.
Once I am more experianced working with this 3rd person package + PUN I will definetly be upgrading to the top of the line edition.

Have a great day from Ben in Tasmania.
 

Attachments

  • awesome.png
    awesome.png
    606.3 KB · Views: 9
I have progressed over the last 4 hours or so but I have run into another problem, in my above post I thought all was fixed, but it turns out what has happened is now that I have implemented a script onto my main character which I derived from reading on the Health attribute page. ( I will add a picture of this script)

Now what has happened is my Damage zone scripts will only take one piece of health off of a player, until he leaves the damage zone and then returns to it. If the character enters in and out of the Damage Zone area until all his health is gone, he does not die.

he is still killable by other players - unless he has already gone to no health using the in-and-out method of the damage zone.

I am also setting the spawn grouping successfully, when I have this script active when one player kills another they spawn at the correct spawnpoint, but it also means the only way for a player to die is from another player.

Fall damage does work to kill you, but it counts as being killed by a player and thus spawns you as if you have been shot.
 

Attachments

  • 1.png
    1.png
    883.2 KB · Views: 10
  • script.png
    script.png
    61.3 KB · Views: 11
I don't see any reason why your DamageAndKill script should have any effect on a Damage Zone... are you sure that's the component that's causing the issue? (Disable/enable it to test.) As for the fall damage, when a character takes fall damage it will pass their own gameobject as the `attacker` argument, so you may need to find a different way of detecting if the character died from landing. I haven't looked into registering to it externally, but there is an OnCharacterLand event that you could register to (see the bottom of CharacterHealth.cs for a bit more).
 
I don't see any reason why your DamageAndKill script should have any effect on a Damage Zone... are you sure that's the component that's causing the issue? (Disable/enable it to test.) As for the fall damage, when a character takes fall damage it will pass their own gameobject as the `attacker` argument, so you may need to find a different way of detecting if the character died from landing. I haven't looked into registering to it externally, but there is an OnCharacterLand event that you could register to (see the bottom of CharacterHealth.cs for a bit more).
The line that breaks it (still compiles and runs, just doesn't 'work') is the 44th line, "if (attacker.tag == "Ben")
but I have no idea how to check what the attacker object was and change the grouping without that line.

I can change the grouping just fine to 99 so long as I don't include that if statement.
I have tried going by name as well but the same problem happens.

I was hoping to do a check so if the tag was player ("Ben" lol) it would send them to 99, but if they died from the environment to send them to 22.
I know its the 44th line 100% because if I change it to if(1<2) it works fine again.

Thanks for the replies Justin and Andrew it's really been helping me out a lot.

In the picture in this post the line that stuffs it up is line 40, its the same script but I use OnDeath instead of OnDamage because it makes more sense, but the problem is the exact same.

In the working script everything is fine, but it means no matter the cause of death you will get grouping 99.
In the not working script, the grouping 99 and respawn still works but all animations and ragdoll are disabled during this time until the respawn is complete.
Also I have no idea how to detect any object other than the player as an attacking object, as you can see in the other small picture the top notice is that the object (my player) took 10 damage at position xyz with force 000 by attacker, attacker doesn't say what the damage zone is called like how it says in the bottom notice xyz, 000 by attacker "man-soldier(clone)" which is my player character.


*edit* line 46 on the right not working script should have an else there I know I was rushing to make the picture.
 

Attachments

  • working_notworking.png
    working_notworking.png
    105.2 KB · Views: 8
  • 11.png
    11.png
    34.3 KB · Views: 8
Last edited:
Firstly you should check if attacker is null before checking its tag, as you'll end up with a null reference error in the case of the DamageZone dealing the damage (the DamageZone will pass null as the attacker gameobject), i.e. if (attacker != null && attacker.CompareTag("ben")... (you should use CompareTag instead of GameObject.tag == "...", it's just a lot faster[/ICODE].

Also since the OnDamage/OnDeath events are a bit limited in terms of the amount of info they provide about the attacker, you might want to think about using the OnImpact event instead (Projectiles and Melee Weapons also send the same event). They give you info about both the attacking gameobject and the object that actually collided to deal damage (in the case of a projectile or melee weapon), so you could use this info to determine what grouping should be applied more accurately.
 
Thank you so much for taking the time to look into this for me.
Your solution worked perfectly. (For the current setup I am working with now)

Today I will be looking into The OnImpact event as you suggested, but as it stands the functionality of how I wanted it to work is perfect now.
Again thank you, you have solved my problem.
 
Top