- Home /
Rigidbody triggers are pushing a CharacterController..
I'm hoping somebody knows what's going on here and can help me figure out out- because it's a really intermittent problem that's bugging the hell out of me.
In my game, I'm using a large SphereCollider as an "aggro" trigger for an AI unit. It has a rigid body on it that is set to Kinematic, because A) it's not static, and B) if the player is standing still and the AI unit patrols past him, I still want the trigger to fire.
So therein lies the problem really- about 2% of the time, the trigger will actually push the player. It's very subtle- just a nudge, but it's obvious. Sometimes it's more than subtle and it seems like the collider is acting as an actual collider and not a trigger.
It's also worth noting that my player has a large sphere collider of his own to use as a 'targeting' trigger. It also has a rigid body set to kinematic. The player's targeting trigger is much larger than the AI's aggro trigger, and when these strange interactions happen, the AI's aggro trigger is always inside the player's targeting trigger. So the 'push' that happens is always the aggro trigger against the character controller (which also has a kinematic rigidbody attached).
Anybody have any idea what is causing this? I've spent the past week off and on trying to search for solutions and fix this issue once and for all, but I'm getting to the point where I feel like I've tried everything.
I updated the question title to hopefully be a bit more descriptive so someone will see it and give me a hand ;)
Answer by testure · Aug 04, 2011 at 05:02 AM
This seems to have gone away with the passage of time. Still no idea what caused it, I can only assume I'm the victim of some freak unity bug.
Closing this question out since nobody had any suggestions anyway :P
Answer by AlanChatham · Jun 22, 2011 at 05:14 AM
I'm a beginner, so this may not be totally correct. But I'm using this setup for my enemy spawn points, and it's working, so I have a bit of confidence in the answer. Is there a reason that you've got your sphere colliders set up as rigidbodies? If you're only using them as triggers, my understanding is that you just have the collider, tick the "Is Trigger" box, then when it interacts with other rigidbodies (i.e. other monsters, the player). So as long as you're not trying to make their aggro triggers interact with other triggers, remove the rigidbodies, and they'll still register trigger events, but won't be trying to push your stuff around.
A trigger is a trigger, so long as the checkbox is ticked. If you're moving a trigger, while not required, if you don't add a rigid body to it, your scene graph is recalculated each frame that the trigger/collider is moving. This can be a HUGE performance killer.
As you get further along with unity, you'll hear that a lot- 'never move a static trigger', and that's the reason. The way you make a non-static trigger is by assigning a rigid body to it and making it kinematic, so that PhysX knows how to track it properly in the scene graph and doesn't have to recalculate each frame.
It's also worth mentioning, that if you don't have a rigid body on a moving trigger, when it moves across a static object that is also lacking a rigid body, it will not register a trigger. For example- if you have a trigger on an AI unit that is walking around, and you have your player stand in the AI's path, the AI will not be able to register a trigger from it unless one of the two have a rigid body attached.
Thanks for the post, and the bump ;)
Wow, thanks for the info! I'm just noticing where the documentation says "These are GameObjects that do not have a Rigidbody attached, but do have a Collider attached. These objects should remain still, or move very little". I'm sure you've already thought about it, but I'm wondering if it'd be possible to add a second child collider to your player controller, then set up the collision filters on the AI aggro spheres to only deal with that? I know that's much more a workaround than an actual solution to what's going on with your game...
Answer by Sungold · Aug 03, 2017 at 05:12 AM
It's happening to me to when my character holsters his firearm. The firearm's collider is set to trigger, but when he puts it away, it pushes the character controller. I put them on different layers and unchecked interaction in the physics tab, and I even modified my movement script to ignore collisions with gameobjects of that layer. No avail.