Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

var detectCollisions: bool;
bool detectCollisions;
detectCollisions as bool

Description

Determines whether other rigidbodies or character controllers collide with this character controller (by default this is always enabled).

This method does not affect collisions detected during the character controller's movement but rather decides whether an incoming collider will be blocked by the controller's collider. For example, a box collider in the scene will block the movement of the controller, but the box may still fall through the controller if detectCollisions is false. This property is useful to disable the character controller temporarily. For example, you might want to mount a character into a car and disable collision detection until it exits the car again.

	var c : CharacterController;
	c = GetComponent(CharacterController);
	c.detectCollisions = false;
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public CharacterController c;
    void Example() {
        c = GetComponent<CharacterController>();
        c.detectCollisions = false;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public c as CharacterController

	def Example() as void:
		c = GetComponent[of CharacterController]()
		c.detectCollisions = false