- Home /
[fixed] OnTriggerExit never called if I change Character Controller center in-script...
Hello-
I have a setup in 2d where I need to know when my player (which has a character controller, and attached movement script) ENTERS and EXITS an invisible trigger box. I put a script on the box with an OnTriggerEnter() and OnTriggerExit(), and it works fine, until I started changing the Character Controller center inside the movement script: now, OnTriggerEnter() is getting called every few frames, while OnTriggerExit() is never called....... I'm constantly changing the center based on if the player is crouching or not. The specific section of the code giving trouble looks like this:
void Update(){
if(crouching){
controller.center = new Vector3 (0, 0, 1.78f); //this is the problem
controller.height = 4.36f;
} else{
controller.center = Vector3.zero; //this is the problem
controller.height = 6.92f;
}
//...
//movement and other things
}
I could try to find a workaround, but if someone could give some insight into fixing this problem, I would greatly appreciate it!
Answer by grangerave · Dec 25, 2012 at 10:01 PM
I updated it to only change the charactercontroller center once using an if statment, all problems went away!
Answer by ofusion · Nov 18, 2015 at 11:16 AM
I meet the same problem. I verify that change CharacterController's center is indeed the reason that trigger's OnTriggerExit is not called.
It is probably a Unity bug. I am using Unity 4.6.6p4, the bug still exists!
Your answer
Follow this Question
Related Questions
Why is OnTriggerEnter2D executing multiple times before I get an OnTriggerExit2D? 1 Answer
mesh collider inside character controller 0 Answers
OnTriggerExit not triggered when object/trigger inside is destroyed c# 1 Answer
Make object react to certain triggers only 1 Answer
Box collider with strange behaviour 1 Answer