- Home /
Per-polygon ray tracing?
Hi all.
In a shooter game, you'll want your bullets to collide per-poly, so in Unity terms, you'll have to use a mesh collider. However, You also don't want all the physics to be per-poly, due to the effect on performance. The question is, can this be achieved with unity? Using per-poly for raycasts while using simpler shapes (e.g. boxes) for movement and collision?
Answer by GameVortex · Feb 06, 2014 at 02:10 PM
Absolutely. Using layers and the collision matrix to select which layers collide with each other.
In the **layer settings** create one layer named "Mesh" (As an example only, name it what you want).
Uncheck all the toggle buttons in the **Collision Matrix** that has to do with the "Mesh" layer (Both the horizontal buttons and vertical buttons). This ensures that no physics calculations will be done on the "Mesh" layer.
Add the mesh collider and set the GameObject to be in the "Mesh" layer. Add the generic collider to a parent GameObject and set the layer to "Default".
When you raycast to shoot now, only raycast against the Mesh layer with:
Physics.RayCast(ray, out hit, distance, layerMask);
Well, I gotta admit, I hadn't thought of that. It works, but it's a lot of pain to set up, so building on top of it, here's what I think would be the best solution: add the gameobjects as usual, then have a (editor?) script find all meshes and add mesh colliders to them, as new gameobjects parented to the original meshes. Thanks man, that really helped me out!
Your answer
Follow this Question
Related Questions
How to use a Raycast to see the distance traveled within a collider. 2 Answers
Move player to specific location and avoid obstacle. 2 Answers
Im trying to create a word game with a twist 0 Answers
Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers
ball sometimes goes through the bat when hit... collider problem... How to do a Raycast? 0 Answers