Such a problem, I make a game on Unity, a game of horror and there is an AI in it that is looking for a player throughout the house. There are doors in the game. How to make it so that the AI can open the doors, moreover, just standing in front of it?
1 answer
The most galley and easiest to implement way is to use a trigger. Make a caper capsule larger than NPC, put the parameter "IsTrigger" on it, create the tag "DOOR" and make a script in which we write:
public void OnTriggerEnter(Collider other) { if (other.transform.tag == ("ДВЕРЬ")) (Метод для открытия двери); }
- You can also force NPCs to close their doors behind them using
protected virtual void OnTriggerExit(Collider other) {if (other.transform.tag == ("ДВЕРЬ")) (Метод для закрытия двери);}- TheFrankyDoll
|