I am making a first person shooter for PC and possibly web player, with a lot of objects in the scene at one time.
I am using sphere/box/capsule colliders for the physical collision detection as I have read that they are faster than mesh colliders. But for detecting bullet hits (raycast and rigidbody) this won't be precise enough, and really I need the precision of a mesh collider. I am thinking of putting mesh colliders on everything that is meant to be hit by bullets, and putting these colliders on a seperate layer that only collides with projectiles.
Will this have a large affect on performance? I know mesh colliders are slow but surely if it is only colliding with one layer the physics engine will have a lot less to do each frame? Also, as a lot of these mesh colliders will be on rigidbodies, will that make a difference?
So, please could someone answer these three questions:
How much will a lot of mesh colliders affect performance?
Will putting the mesh colliders on a layer colliding with only one layer (or even no layers, as I could easily make the projectile weapons use raycast instead) improve their performance?
Does it matter if a mesh collider is on a rigidbody?
Answer by Lovrenc
Jul 31, 2013 at 06:11 PM
Well you can allways go and check how game would behave with mesh colliders and then return back. But beware, autogenerated mesh colliders will not necessarilly be "precise".
That said, i don't know if this changed, but at least all old FPS never used mesh colliders and i doubt you noticed it. Look at quake 3 hitbox. It is not very representative of a character yet i doubt you can really notice:
Here are some other examples. A little more precise from other games.
Thank you for answering so quickly,
I will go and check with mesh colliders, it's just that I don't really have enough objects in the game for it to make a big difference. I'm not using mesh colliders for player collisions though, just for detecting bullet hits. For normal collisions I am just using normal colliders. Will this make a difference, or does the layer collision matrix not have an effect on performance?
Of course it has an effect. It is like a filter so it reduces load if used properly.
What do you mean exactly by: "for detecting bullet hits"?
In the picture you posted, would those hitboxes be used for detecting bullets, or just collisions?
That helps a lot. So using mesh colliders that don't actually collide will make them a lot faster. So all I need to know now is how using these non-colliding mesh colliders with rigidbodies would change things.
Answer by rokyed
Aug 16, 2013 at 03:20 PM
You can also take a look to Counter Strike Source or Half Life 2 hitboxes : they look like this
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
18 People are following this question.
Raycast hitting the incorrect layer
raycast from an empty gameobject?
NullReferenceException: Object reference not set to an instance of an object Raycast...?
Hit Angle Of Ray to Surface?
If collider between two points get this point