Camera being affected by sphere collider triggers
Hey all,
I have a strange problem, maybe I'm missing something obvious, but I can't seem to figure it out.
I have an FPS controller with a camera attached. On the camera is a rigid body. This rigid body uses both gravity and is kinematic (in fact, this is simply the default FPS controller that comes in Standard Assets with Unity 5.1.1).
Now, I have a bunch of sphere colliders in my scene, about 400 or so. They are set to Triggers, with a radius of 100. At the scene opening, the camera is inside about 140 of these triggers. I have routines for OnTriggerEnter and OnTriggerExit (nothing in OnTriggerStay, so there is nothing continuously firing).
I'm given to understand that since I have these set as triggers, they should have no effect on the physics of the camera. However, as I move the camera, it weaves around like it's my drunk uncle. Sometimes the controller even gets pushed through the floor.
I've definitely isolated it to those triggers. If I turn them off, the camera moves around just fine. And it's nothing inside the scripts either, I commented them out, and the weaving behavior continued regardless. So it really seems to be that the colliders are affecting the camera, even though the docs say they shouldn't be.
So what gives? What am I doing wrong? Why is the camera movement being affected by these sphere colliders that are set to be triggers?
Thanks for any help. Probably just something dumb I'm doing.
Well, I have more information, if anyone is interested or runs into the same problem.
I set up a new test scene. Just the FPS Controller (from Standard Assets/Characters), a scaled box acting as the floor (1000, 1, 1000), a few cubes to act as references, and about 100 empty game objects. On those, I stuck a sphere collider, checked the "IsTrigger" box, and set the radius to 100. I put those at various locations/elevations in the scene.
Oh, and I turned off the "Head Bob" on the camera so I could see more clearly what was going on.
Turned off the triggers, and walked straight as an arrow through the reference boxes. Turned them on, and I got pushed around. Just like in my scene. Absolutely no code, other than what is on the FPS controller.
So then I replaced the FPS controller with the other one that is in standard assets, which is "RigidBodyFPSController". And behold, the problem went away! Walked straight through the boxes, triggers and all.
So at this point I suspect there is a bug in the FPSController script that is causing the physics of the camera movement to be affected by triggers. I haven't tracked it down (and I probably wont, I wasn't planning on using that asset anyway, it was just a temporary placeholder until I write my own camera controller).
Perhaps this is a known issue, but I looked and didn't see any discussion about it. So if anyone runs into the same problem, it appears to be something in the FPS controller code. Either switch over to using RigidBodyFPSController or go debugging through that code (or write your own camera system, heh).
Your answer
Follow this Question
Related Questions
Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer
Update meshCollider send OnTriggerExit 0 Answers
How to trigger functions like OnTriggerEnter2d and OnTriggerExit2d with raycasthit2d ? 1 Answer
triggered sound playing on start 0 Answers
How Do I increase speed based off of a trigger collider? 0 Answers