Search Unity

Pass through enemy error

Discussion in 'Getting Started' started by IvanDonets, Nov 6, 2015.

  1. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    I'm making a 3d game, and there are enemies. When I approach them, I use OnTriggerStay or OnTriggerEnter functions for SendMessage (to get damage and attack). But problem is that collider of enemy is set to trigger, so that a Player passes through the enemy. I want the similar functionality but Player should not pass through enemy.
    Anyone knows how to fix that?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Can't you just switch from triggers to colliders, and use the OnCollisionStay and OnCollisionEnter methods?

    Or, what I've done in some games: have two colliders (or sets of colliders) on each agent: one is a true physics collider, and the other (usually larger) is a trigger. Then I can do triggery things even before the objects actually touch, and still get proper physics when they do.