Facebook

Cylinder Collider in Unity

by Liam Cubicle Published January 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.

This is a series on Unity Physics. We recommend reading the series in order.

  1. Unity Physics
  2. Unity Collision Detection
  3. Character Controller and Input Systems
  4. Rigidbody Mass in Unity
  5. How to add Friction to a Rigidbody
  6. Cylinder Collider in Unity
  7. Box Collider in Unity
  8. Box Cast in Unity
  9. Sorting Layers
  10. Get the distance between two objects
  11. How to normalize a vector

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!

Free download: Indie Game Marketing Checklist

Download now

Category

physics

Don't forget to share this post!

Popular assets for Unity

See all assets ->
    Cutting-edge volumetric fog and volumetric lighting with support for transparent materials.
    Volumetric clouds, day night cycles, dynamic skies, global lighting, weather effects, and planets and moons.
    A lightweight procedural skybox ideal for semi-stylized projects.
    Image-based Outlines for 2D and 3D games with variable line weight, color, and displacement options.
    Per-pixel gaussian blur on your entire screen, part of the UI, or in-scene objects.
    Drag-and-drop ready-to-use ambient, impact, and spell particle effects.

Free Indie Game Marketing Checklist

Learn how to make your game successful with this handy checklist.

Download for free