- Home /
How can I destroy my Player if only his Head or Body touch the ground.
I want to destroy my Player when his Body or head touch the ground. And when he stand on his feet it should not destroy. Please Help me.
Answer by prakyathd801 · Dec 29, 2020 at 01:10 PM
1.Add two separate colliders Player and adjust it it to fit with Body and Head.
2.Add collider to ground
3.Change Tag of the Ground and Player
4.Attach below code to Ground
private void OnCollisionEnter(Collision other)
{
if(other.tag == "Player")
{
Destroy(other.gameObject);
}
}
Yes I tried this but my Player also destroyed when the Collider on his feet touch the Ground and I dont want that. Something like a metod that the Player should destroy when only the BoxCollider of the Player touch the Ground and not all Coliders
void OnCollisionEnter2D(BoxCollider2D other) {
if (other.gameObject.tag == "Player") {
Destroy(other.gameObject);
}
}
Answer by sacredgeometry · Dec 28, 2020 at 11:49 PM
Put colliders on the head and torso and then test for them.
Answer by Ethanruff · Jan 04, 2021 at 10:18 PM
Just put different colliders on the feet and legs, and have the torso and head colliders kill on touching the ground.
Your answer
Follow this Question
Related Questions
collision wont work 1 Answer
collision with wall so player dies 1 Answer
Destroy character when collision with enemy 3 Answers
[Closed]Not destroying floor? 1 Answer
Player not getting destroyed when touched by enemies 4 Answers