Quantcast
Channel: Answers for "Help getting player killed when enemy collides with him"
Viewing all articles
Browse latest Browse all 6

Answer by gamenovice

$
0
0
I am assuming that you have colliders set up on both your character and your enemy for this. normally what you should do is check if a collision occured between your player and the enemy, after that, check the tag of the object that collided with your player. if it matches the tag 'enemy' for example, then you would proceed to go on with the logic that kills your player (I'm not sure what it is your looking for with the actual death sequence, so more info on that would better refine this answer). in code it would look something like this (write this code somewhere in your main script, probably the player script or manager script or something): //im using c# for this implementation, but there should be a javascript equivalent //you will check for a collision that enters your player object, with a reference to the collision itself as the parameter void OnCollisionEnter(Collision c) { //here we check for the collider involved in the collision, and check its tag //if it matches enemy, proceed with the logic if(c.collider.tag == "enemy") { //here you would proceed with the death sequence, since i dont know what it is, i made a template with a debug statement Debug.Log("the player has died"); } } hope that helps! let me know if you have any further questions at gamenovice@gmail.com!

Viewing all articles
Browse latest Browse all 6

Trending Articles