Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

enemy aggro through wall fix theorys

Discussion in 'Scripting' started by Resilo, Dec 27, 2017.

  1. Resilo

    Resilo

    Joined:
    Dec 8, 2016
    Posts:
    139
    So my enemies have a box collider that tells them when a player has entered the aggro range

    problem is the collider goes through the wall because is trigger must be on to work correctly with
    the attached script and causes them to walk into walls after the player

    what is some methods you could theoretically use to prevent this from occuring?
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    You can use the trigger to detect the wall and stop the enemy with a script.
    You can have the trigger on an object, and notify the enemies when the player has entered, then they can have collision.
    You can have two colliders on the enemy, one for trigger and one for collision, but they might need to be stacked or something.
    What's most common, though, is to do a distance check to the player.
     
    Last edited: Dec 27, 2017
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    What I would do:

    - Collider detects player is in range or a distance check(trigger might be more efficient need to do more testing).
    - Enemy then starts performing Raycasts to check for LOS, put this in a coroutine or other timed check as long as player is in range to keep polling LOS. Timed as it doesn't need to happen every update, adjust timing to your liking.
    - When LOS achieved then do action.
     
    TonyLi likes this.