Colliders are like the bedrock of the Unity Physic Engine. They are different types of colliders based on their shape configurations. There’s the box, sphere, mesh, capsule, and wheel collider. There’s also the cylinder collider but it’s not available primitively in Unity.
In this article, you will learn everything you need to know about cylinder colliders in Unity.
What are Cylinder Colliders?
Cylinder colliders are useful for humanoid-shaped and cylinder-shaped objects like; discs in Unity. However, this type of collider is not available in Unity primitively like the box, sphere, and capsule collider as of now. Why is this so?
It’s said that cylinders are much harder to work with than spheres, capsules, or boxes. This is because it involves using a mesh involving more vertices and computations. Therefore, it’s computationally expensive.
Due to this limitation, Unity game developers have found several ways around this limitation as cylinder colliders are indispensable. This article will provide you with useful ways to deal with this limitation.
Here are some of the ways to produce a cylinder collider in Unity;
Use the cylinder mesh in Unity with a convex mesh collider
- In the Unity Editor, go to the GameObject menu and choose a 3D object. Then, select Cylinder.
- Adjust the size and scale of the Cylinder in the Transform component.
- Now, to add a convex mesh cylinder component to the Cylinder GameObject, select the Cylinder GameObject in the Hierarchy click on “Add Component” and search for “Mesh Collider” in the Inspector window.
- Then, check the Convex checkbox.
- Modify the properties according to your specifications.
- You can now test your newly created cylinder collider in Play mode.
By following these steps, you have successfully created a cylinder collider with the primitive cylinder mesh coupled with the convex mesh cylinder component.
Create a cylinder mesh in Blender and export it to Unity
- Create a simple cylinder mesh in Blender and save it as a “.obj” file.
- Import the file into your project’s Assets folder in Unity.
- Drag the imported file into your Unity scene and attach it as a parent to the GameObject you need it for.
- Then, add a convex mesh collider to the GameObject as explained earlier.
By following these steps, you have successfully created a new cylinder collider which you can now test in play mode.
Use a Paid Asset like Cylinder Collider Builder
Using mesh colliders can limit performance, so you could look into tools that may have more optimizations built-in. One example of such a tool is the Cylinder Collider Builder on the Unity Asset Store.
This tool is useful for building a 3D cylinder collider based on box colliders. All you need to do is set the height, radius, and total number of box colliders. Then, the tool will do the building for you. You can visit the Unity Asset store to purchase and download this asset.
Now, you should be able to create a cylinder collider with any of these three methods. We hope that a primitive cylinder collider will be added to Unity as time goes by. In the meantime, happy coding!