- Home /
C# Rocket Explode On Impact
Hi! I am working on a FPS game and, more specifically, implementing a rocket launcher. Is there any way of making it so my rocket explodes on impact with any surface, without having to use different Tags and colliders?
Thanks in advance!
Comment
Answer by Lost_Syndicate · Oct 23, 2018 at 03:24 PM
Just do
private void OnCollisionEnter(Collision collision)
{
// instantiate the explode particle here
// OR if you want splash damage of some sort
Health health = collision.collider.gameObject.GetComponent<Health>();
if (health != null)
{
if (Vector3.Distance(collision.collider.gameObject, transform.position) < range)
{
health.TakeDamage(damage);
}
}
Destroy(gameObject);
}