- Home /
Use trigger collision or position check?
The context is:
mobile and browser game (performance!);
2.5D Top down perspective (camera sees Y-);
Movement from top to bottom part of the screen (the main character actually moves "bot-up");
I got this scenario elements moving at the background of the game. They're just planes with a texture. I removed the mesh collider from them. And they're created beyond top border of the screen and the camera movement makes them appear moving beyond the bottom border of the screen. No big deal until there.
When they reach a position beyond camera's field of view I wan to destroy or relocate them and I know how to do both. My question is about what would cost less in terms of processing to check if the scenario element has reached a position in relation of the camera's current position (over the Z+ axis BTW).
If I setup a object at that position to collide with the planes, and change the collision matrix to make the scenario elements just collide with this "game bottom border" would be a good solution? Or attach a simple script to each plane with a camera reference and each frame (or skipping one or two frames to save processing) check its relative position to the camera to know when destroy itself would be better thinking about the performance on mobile devices?
Thanks for your help.
Answer by Sisso · Nov 26, 2012 at 01:53 PM
The real answer you only know doing a performance test in a real device.
I think that both options are ok. Checking the object position relative to camera is one matrix multiplication. But collider could be optimized by the engine.
Personally I give a try in the first one.
You're right about the tests, but the reason I asked was to save some work. And anyway I will only be able to do some testing in a week or so.
If the game runs on mobile, it will not take advantage over PhysiX, right?
Yes and worse, aparently unity3d always cpu ( http://answers.unity3d.com/questions/209646/is-physx-being-used-on-mobile.html ). But physic is always very optimized, so, could be faster.
So, under that light, the position check is simpler calculations than collision and therefore cheaper? $$anonymous$$ind that every scenario object must have one reference to the main camera using that approach.
It is my opinion :P References will not be a problem if cached in Start().