unity3d Collision Colliders


Example

Box Collider

A primitive Collider shaped like a cuboid. Enabled and disabled Box Colliders

Properties

  • Is Trigger - If ticked, the Box Collider will ignore physics and become a Trigger Collider

  • Material - A reference, if specified, to the physics material of the Box Collider

  • Center - The Box Collider's central position in local space

  • Size - The size of the Box Collider measured in local space

Example

// Add a Box Collider to the current GameObject.
BoxCollider myBC = BoxCollider)myGameObject.gameObject.AddComponent(typeof(BoxCollider));
 
// Make the Box Collider into a Trigger Collider.
myBC.isTrigger= true;

// Set the center of the Box Collider to the center of the GameObject.
myBC.center = Vector3.zero;

// Make the Box Collider twice as large.
myBC.size = 2;

Sphere Collider

A primitive Collider shaped like a sphere. Enabled and disabled Sphere Colliders

Properties

  • Is Trigger - If ticked, the Sphere Collider will ignore physics and become a Trigger Collider

  • Material - A reference, if specified, to the physics material of the Sphere Collider

  • Center - The Sphere Collider's central position in local space

  • Radius - The radius of the Collider

Example

// Add a Sphere Collider to the current GameObject.
SphereCollider mySC = SphereCollider)myGameObject.gameObject.AddComponent(typeof(SphereCollider));
 
// Make the Sphere Collider into a Trigger Collider.
mySC.isTrigger= true;

// Set the center of the Sphere Collider to the center of the GameObject.
mySC.center = Vector3.zero;

// Make the Sphere Collider twice as large.
mySC.radius = 2;

Capsule Collider

Two half spheres joined by a cylinder. Enabled and disabled Capsule Colliders

Properties

  • Is Trigger - If ticked, the Capsule Collider will ignore physics and become a Trigger Collider

  • Material - A reference, if specified, to the physics material of the Capsule Collider

  • Center - The Capsule Collider's central position in local space

  • Radius - The radius in local space

  • Height - Total height of the Collider

  • Direction - The axis of orientation in local space

Example

// Add a Capsule Collider to the current GameObject.
CapsuleCollider myCC = CapsuleCollider)myGameObject.gameObject.AddComponent(typeof(CapsuleCollider));
 
// Make the Capsule Collider into a Trigger Collider.
myCC.isTrigger= true;

// Set the center of the Capsule Collider to the center of the GameObject.
myCC.center = Vector3.zero;

// Make the Sphere Collider twice as tall.
myCC.height= 2;

// Make the Sphere Collider twice as wide.
myCC.radius= 2;

// Set the axis of lengthwise orientation to the X axis.
myCC.direction = 0;

// Set the axis of lengthwise orientation to the Y axis.
myCC.direction = 1;

// Set the axis of lengthwise orientation to the Y axis.
myCC.direction = 2;

Wheel Collider

Properties

  • Mass - The mass of the Wheel Collider

  • Radius - The radius in local space

  • Wheel damping rate - Damping value for the Wheel Collider

  • Suspension distance - Maximum extension along the Y axis in local space

  • Force app point distance - The point where forces will be applied,

  • Center - Center of the Wheel Collider in local space

Suspension Spring

  • Spring - the rate at which the Wheel tries to return to the Target Position

  • Damper - A larger value dampens the velocity more and the suspension moves slower

  • Target position - the default is 0.5, at 0 the suspension is bottomed out, at 1 it is at full extension

  • Forward/Sideways friction - how the tire behaves when rolling forwards or sideways

Example


Mesh Collider

A Collider based on a Mesh Asset. Non-convex and convex Mesh Colliders

Properties

  • Is Trigger - If ticked, the Box Collider will ignore physics and become a Trigger Collider

  • Material - A reference, if specified, to the physics material of the Box Collider

  • Mesh - A reference to the mesh the Collider is based on

  • Convex - Convex Mesh colliders are limited to 255 polygons - if enabled, this Collider can collide with other mesh colliders

Example


If you apply more than one Collider to a GameObject, we call it a Compound Collider. enter image description here