- Home /
3d ground for 2d gameplay / side scroller
Hi. I am new to Unity and have a question on the best way to do this. I plan on building a long thin mesh in blender to act as my ground and then scroll along this for some 2d game play.
From what I can tell the best way for me to detect a collision with this mesh is to add a Mesh Collider to it and then use Physics.RayCast to test for a collision. (please let me know if there is a better approach).
My question is, if I create a big mesh like this will Unity optimize the data well enough that I do not have to worry about breaking up the mesh into smaller meshes to handle the collision lookups which will occur several times every frame or do I need to try and limit the size of each mesh so that it can cull out the objects faster before it does any triangle level collision detection?
Is there a better way to do this?
Thanks.
Answer by aldonaletto · Oct 07, 2011 at 01:03 AM
You should use the mesh collider, but there's no need to Raycast: if you use a CharacterController in your character, it will automatically detect ground collisions and walk over your mesh collider without falling through.
About the mesh, it's a good idea to break it in smaller pieces and import each one as a separated object - you can have better texture resolution, and segments out of the viewing volume will not be rendered, improving performance (Unity does frustum culling automatically). Segments a little larger than the screen seem to be a good choice, since at most two mesh segments will be rendered each frame.
I forgot to mention: you can child all ground objects to a single empty object - the frustum culling works for each object, even when they are part of a common parent.
great, thank you. I am planning on flying over the ground which is what led me to the ray cast, planning to use this to get my altitude.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000610im_/https://answers.unity.com/themes/thub/images/avi.jpg)