Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

CharacterController.detectCollisions

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var detectCollisions: bool;
public bool detectCollisions;

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.

#pragma strict
public class Example extends MonoBehaviour {
	var controller: CharacterController;
	function Start() {
		controller = GetComponent.<CharacterController>();
		controller.detectCollisions = false;
	}
}
using UnityEngine;

public class Example : MonoBehaviour { CharacterController controller;

void Start() { controller = GetComponent<CharacterController>(); controller.detectCollisions = false; } }

Did you find this page useful? Please give it a rating: