- Home /
How can i make a projectile attack travel through multiple enemies dealing damage to all of them?
I'm making a 2D game where a few attacks need the ability to travel through multiple enemies, but no matter how i seem to try to set up the colliders and rigid body, it always stops at the first enemy hit.
thanks In advance!
Set the projectile collider property IsTrigger = true. That way the collider behaves like a sensor and you can process the hits with OnTriggerEnter (ins$$anonymous$$d of OnCollisionEnter).
Answer by BloodBTF · Jul 06, 2016 at 02:26 PM
Use this.
 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public Transform bulletPrefab;
 public Transform[] enemyObjects; //put all your enemy objects in here
     void Update() {
 foreach  (Transform enemy in enemyObjects)
 {
         Transform bullet = Instantiate(bulletPrefab) as Transform;
         Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), enemy.GetComponent <Collider2D>());
 }
 }
 }
It's not the best, but it's all I can do and much more efficient than setting it to trigger
Your answer
 
 
             Follow this Question
Related Questions
Projectiles, their speed, and collisions 1 Answer
Jumping on top of an enemy problem 1 Answer
Spawner continuing after boss dies 1 Answer
collider affect collider problem 0 Answers
Enemy Detection Area 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                