CodeBlanks Logo Icon CodeBlanks

What is a Collider?

Learn collision shapes like Box Collider and Sphere Collider.

What is a Collider?

Collider components are invisible collision volumes defining a GameObject's physical boundaries. Without a Collider, other objects pass right through it like a ghost.

// Adding a box collision boundary
BoxCollider box = gameObject.AddComponent<BoxCollider>();
box.size = new Vector3(1f, 2f, 1f);

The visual 3D model and physical collision volume are decoupled; MeshRenderer draws the visuals, while Collider governs collisions.

Primitive and Complex Collider types

The most common primitive types are BoxCollider, SphereCollider, and CapsuleCollider. These primitives are mathematically very fast to compute.

// Setting SphereCollider radius
SphereCollider sphere = GetComponent<SphereCollider>();
sphere.radius = 0.5f;

A MeshCollider wrapping every polygon vertex is much more costly, so it is generally reserved for static environment assets.

Practice Print Collider profile

Assign "SphereCollider" to colliderType and "0.5" to radius. Print Collider: SphereCollider | Radius: 0.5 to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // colliderType ve radius değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        string colliderType = "SphereCollider";
        string radius = "0.5";
        Console.WriteLine("Collider: " + colliderType + " | Radius: " + radius);
    }
}

Expected output

Collider: SphereCollider | Radius: 0.5

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which component is most appropriate for defining collision bounds of a spherical object?

  • CanvasScaler
  • NavMeshObstacleOnly
  • SphereCollider Correct answer
  • AudioReverbZone

Explanation: SphereCollider provides the most optimized collision check for spherical geometry using center and radius.

2 Attach SphereCollider component

Question
SphereCollider sphere = gameObject.AddComponent<____>();
Answer
SphereCollider sphere = gameObject.AddComponent<SphereCollider>();

Explanation: In Unity, SphereCollider is passed as the generic type when attaching a spherical collision component.

3 Collider types

Term Meaning
BoxCollider Box-shaped collision volume
SphereCollider Sphere volume defined by radius
CapsuleCollider Capsule collision for character bodies
MeshCollider Collision following model surface

All lessons in Beginner