- Home /
Question by
Rubenn · Sep 23, 2016 at 04:56 PM ·
car physicsenemy healthenemy damagezombiescontrollercolliderhit
How do i Kill Enemy with Vehicle??
Hello,
i am using realistic car controller and Advanced AI pro. How do i fix that the enemy dies after i hit him with the car? I can shoot it but cant drive him dead.
Comment
Answer by SohailBukhari · Sep 23, 2016 at 05:59 PM
@username Give tag to the enemy and use OnCollisionEnter Method to detect that car hit enemy tag , When collision detected Set Some Status of enemy
void OnCollisionEnter(Collision collision)
{
if (collision.transform.CompareTag("car"))
{
// here you can add rigid bodycomponent to give effects
or simply destroy
}
}
Answer by Keyo · Sep 24, 2016 at 11:34 AM
You'd put the script below on the Enemy, and tag your car as "MyCar". More documentation about OnCollisionEnter can be found here.
https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
public class Enemy
{
void OnCollisionEnter(Collision c)
{
if (c.transform.CompareTag("MyCar"))
{
Destroy(gameObject); // Destroy this enemy
}
}
}