← Back to blog physics

Cylinder Collider in Unity

by Michael Sacco Jan 25, 2024
The cover for Cylinder Collider in Unity

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

  1. In the Unity Editor, go to the GameObject menu and choose a 3D object. Then, select Cylinder.
  2. Adjust the size and scale of the Cylinder in the Transform component.
  3. 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.
  4. Then, check the Convex checkbox.
  5. Modify the properties according to your specifications.
  6. 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

  1. Create a simple cylinder mesh in Blender and save it as a “.obj” file.
  2. Import the file into your project’s Assets folder in Unity.
  3. Drag the imported file into your Unity scene and attach it as a parent to the GameObject you need it for.
  4. 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.

Conclusion

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!

Continue reading

Non-static method requires a targetHow to make a countdown timer in UnityPricing Strategy for Indie Game DevelopersUnity: How to Change Your SkyboxHow to add Friction to a Rigidbody in UnityUnity Standard Assets: The Essential GuideTop 10 Recent Games Developed with UnityUnity Sprite MasksHow to move or copy a Unity projectThe Ultimate Guide to Sun and Moon Positioning in Super Simple Skybox for Unity

Build your game with OccaSoftware

Learn on the go. Try OccaSoftware for free, and explore all the tools and assets you need to start, build, and launch your game.

Start now

Try OccaSoftware for free, no commitment required.