C
C
CainReveur2019-10-15 12:47:37
C++ / C#
CainReveur, 2019-10-15 12:47:37

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

2 answer(s)
K
Konstantin Kitmanov, 2019-10-15
@k12th

Layer-based collision detection

M
mayton2019, 2019-10-18
@mayton2019

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 question

Ask a Question

731 491 924 answers to any question