# Animator transition doesn't get triggered when the player moves into a trigger area

so i want to open a door with a keypress but it's not changing the 2 bool's state any help?

public Animator _animator;

void Start ()
{
_animator = GetComponent<Animator>();
_animator.SetBool("close", true);
_animator.SetBool("Open", false);
}

void OnTriggerStay(Collider other)
{
if (other.tag == "player")
{
if (Input.GetKeyDown(KeyCode.E))
{
_animator.SetBool("close", false);
_animator.SetBool("Open", true);
}
}
}


• A few suggestions, it would be better if you edited the title of your question to be an actual question of your problem, then we would need some more info to help you. When you say "it doesn't work" does that mean that the door is not moving at all? Are you certain that the animation on the door is properly opening/closing the door but it's just not firing from the code? A screenshot of the Animator and how its configured would really help – TomTsagk Aug 23 '18 at 10:01
• yes it dosen't change the animation state "close to false and open to true" – MonsterLHGoO Aug 23 '18 at 10:15
• but it's working if i use with OnTriggerEnter and no key used but i want this to work when i press the E key – MonsterLHGoO Aug 23 '18 at 10:16
• The first thing I would do to troubleshoot this problem is to find out if the OnTriggerStay function actually gets called. Did you verify this? Also, keep in mind that tags are case-sensitive. "player" is not the same tag as "Player". – Philipp Aug 23 '18 at 10:47
• omg i'm an idiot the problem was the "player"tag :D i didn't noticed that thx so much – MonsterLHGoO Aug 23 '18 at 10:53

I think the problem is being caused by OnTriggerStay() with the GetKeyDown().

Try this:

• Create a new variable

bool isPlayerHere = false;

• Use OnTriggerEnter(), if the player caused it to fire (with the other.tag like you are already doing), set isPlayerHere to true

• Then OnTriggerExit() will set the isPlayerHere to false.
• Now on your Update(), check if isPlayerHere is true, then check for input.

Example code:

// Player just entered the collider, so they are "near" the door
void OnTriggerEnter(Collider other)
{
if (other.tag == "player")
{
isPlayerHere = true;
}
}

// Player just exited the collider
void OnTriggerExit(Collider other)
{
if (other.tag == "player")
{
isPlayerHere = false;
}
}

void Update() {

// Player is inside the collider that can activate the door,
// and also pressed the right key - activate the door
if (isPlayerHere && Input.GetKeyDown(KeyCode.E))
{
_animator.SetBool("close", false);
_animator.SetBool("Open", true);
}
}


As a side note, I could also suggest, instead of having 2 variables "close" and "Open", you could just only one named open, if its value is false then the door is closed, if its true then the door is open. (this also simplifies the Animator implementation)

• thx that really helps me out but the problem was i used the player tag not the Player :D – MonsterLHGoO Aug 23 '18 at 10:55
• @MonsterLHGoO Ouch! haha, well I'm glad the problem is solved :) – TomTsagk Aug 23 '18 at 11:02