- Home /
How to deal with *many* moving colliders?
I have a lot of colliders in my game. And they all move. The main object (the player) is a Rigid Body with isKinematic checked. None of the other objects have a Rigid Body, just a collider (atm a Mesh collider but I'm considering punting and using basics).
Everything is a Trigger.
ALL GameObjects that are colliders (excluding the player) are contained in another empty GameObject so I can transform their locations based on a grid system. Meaning, I do not manually move each Collider itself, I just move its empty parent GameObject.
And due to me moving everything, I do not use any physics in my game.
I have read many conflicting sources that say either:
Many RigidBody's produce heavy performance load
or
Many moving objects with collision should have a RigidBody with isKinematic checked.
I am currently having iOS performance issues and I need to see if I can squeeze as much out of my code as possible.
Can I turn off Physics completely? Or at least enough such that only Trigger collision detection is performed?
Should I keep all collider's as basic colliders or should I put RigidBody's on them with isKinematic enabled?
All colliders fall within 1 of 8 or so basic mesh's (think circle, oval, triangle, hexagon, 4-point star etc) with as few triangles as possible. I currently have "mesh collider" on each of them so that that specific shape is used for collision. Since I have as few triangles as possible, is this ok? Or should I actually just punt and use one of the 3 built-in primitive colliders (Box, Sphere or Capsule)?
Thanks so much!
PAR
Answer by DESTRUKTORR · Apr 21, 2013 at 07:52 PM
No, you cannot turn off unity's Physics engine, but you -can- utilize it more carefully.
OnTriggerEnter
,OnCollisionEnter
, etc. are only called if they are contained within a behaviour that is attached to a game-object with the proper collider/rigidbody arrangement for that method call, so as long as you only use trigger-colliders (colliders with "isTrigger" checked), you should be good.isKinematic
disables all physics effects on the rigidbody, but allows it to affect other rigidbodies. If you want to know whether an object will get a collision call, simply check the corresponding documentation page. Box Collider, sphere collider, capsule collider, mesh collider, and wheel collider are the only ones available, in unity. If there's no physics involved with a given collider, and it's just a trigger, I'd suggest just not using rigidbodies, and sticking to the trigger collider. Otherwise, depending on how complex the physics will be, you may or may not want to use an attached rigidbody.Mesh colliders will not collide with other mesh colliders, unless at least one of them is set as convex. However, mesh colliders -will- collide with other colliders that are -not- mesh colliders, with or without being set to convex. However, stick to built in colliders whenever possible. It will likely improve efficiency by quite a bit, as the system knows exactly what the mesh looks like, and is optimized to use it.
Thanks for the reply DESTRU$$anonymous$$TORR...
I am still quite confused on how to deal with what I am working with.
$$anonymous$$uch of the documentation says that if you have static collision objects to use just a collider on the object and go from there. The documentation also says if you $$anonymous$$OVE a static collider, you will incur a large overhead due to the physics engine needing to .. do whatever it does (I am seeing this now).
I have also read that putting a rigidbody with "is kinematic" checked will remove the overhead seen from dealing with many objects that are also colliders.
What I am seeing is framerates of 50-55 FPS on an iPhone 4 with all colliders and rigidbodies removed (so my graphics are not an issue). As soon as I have my objects use either a plain collider with isTrigger checked OR a plain collider with isTrigger checked AND a RigidBody w/ is$$anonymous$$inematic checked, I drop to 3-5 FPS.
I have spent the past weekend trying to change my entire engine so that I can keep all colliders but the main object (the player) completely stationary but the way the whole system works I just cannot do it. In order to accomplish what I am trying to do (which I did accomplish with Cocos2d and Box2d on the iPhone) I must have everything moving. That is why I asked if there was a way to remove the Physics completely except for the collision.
I wonder if there is a magic combination of things I must do in order to get this to work the way I want. I'm sure Unity and PhysX can do it... I just dont know what it is.
PAR
So after rewriting the way my entire game moves and trial and error, I realized that what Destruktorr was saying was exactly what I needed to utilize.
I ended up going BAC$$anonymous$$ to my old way of moving the world around via leaving the main player stationary and moving the whole world ins$$anonymous$$d (moving individual layers individually would cause rounding errors after awhile... I have to have movement across all layers exact or my world logic doesnt work).
With that strategy I then created everything as a basic collider (either sphere or box) and then put a rigidbody on all of them with $$anonymous$$INE$$anonymous$$ATIC OFF (this surprised me). This produced by far the best results with one caveat...
I had to put in location logic of the colliders. $$anonymous$$eaning, I have to turn off all colliders that never have a chance to collide with the player until there is a possibility of doing so. W/out this logic, my fps is down in the 5-10 range. With the logic I'm rock s$$anonymous$$dy at 48FPS on an iPhone4.
PAR
Your answer
Follow this Question
Related Questions
Are my kinematic rigidbodies slowing my scene down? 2 Answers
Is Use Full Kinematics Contact bugged in 5.6.1? 0 Answers
Simple Movement Game: Physics vs Manual Collision Detection? 2 Answers
Disable rigidbody from being able to move other rigidbodies 1 Answer
[SOLVED] Desactivate pushing forces between two objects 2 Answers