- Home /
Player kill enemy by stepping on it.
Player kill the enemy by stepping on it. Something similar to super mario. How can i go about doing it? I am thinking maybe i might need to add in ridigbody to the enemy kind. I am lost. Please help.
Answer by DeathHawk · Mar 13, 2012 at 06:08 PM
Give a rigid body to player and enemy and some type of collision to each. Then have a collision script on only one of them. Probably the player. Since your stepping on it probably add a collision box to the feet of the player and have the script say something like when the collision happens on enemy then enemy is dead. You will need to get as precise as you need to with this but all the tutorials are there for how to make collision on things then just take that and modify how desired.
Hi thank you for the reply. I am even more confused with what you have mentioned. Would appreciate if you could provide some code snippet for better view?
Answer by Meltdown · Mar 13, 2012 at 06:21 PM
You simply need to add a collider to your player and to your enemy. Once they collide with each other, and your players feet are touching the enemies head, destroy the enemy.
Look at OnCollisionEnter for some code examples.
hmm.. so i just add an collider object to the feet only or the whole gameObject? Yes.. I know how to use the OncollisionEnter. Just don't uunderstand how rigidbody work.
Add a collider to the feet only, and when that collider strikes the enemy destroy it.
Otherwise, you can just compare the y-position of the two objects when they collide, and if one is higher than the other crush the one below.