Answer the question
In order to leave comments, you need to log in
How to make a bullet pass through allies in a 2D platformer?
There is a 2D platformer. It shoots not only gg, but also enemies, how to make the bullet of enemies pass through its allies (objects with the Enemy tag)
void Start(){
player = GameObject.FindGameObjectWithTag ("Hero").transform;
target = new Vector2 (player.position.x, transform.position.y);
if (player.position.x < transform.position.x){
speed = -speed;
}
}
void Update(){
rbeb.velocity = transform.right * speed;
}
void DestroyBullets(){
Destroy (gameObject);
}
void OnTriggerEnter2D (Collider2D other){
PlayerControl player = other.GetComponent<PlayerControl> ();
if (player != null) {
player.TakeDamage (damage);}
DestroyBullets ();
}
}
Answer the question
In order to leave comments, you need to log in
The algorithm for applying damage should be exactly the same for everyone. It's just that the allies should have a multiplier of 0.0 and the enemy, respectively, 1.0.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question