Description
The IgnoreLayers
property of the CharacterController
class is used to specify which layers should be ignored during collision detection. This property is of type TagSet
, allowing you to define a set of tags that represent the layers to be ignored.
This property is particularly useful when you want to customize collision behavior by excluding certain layers from being considered during collision checks. For example, you might want to ignore collisions with certain environmental objects or other characters.
The IgnoreLayers
property is part of the "Collision" group and is hidden if the UseCollisionRules
property is enabled. This means that when UseCollisionRules
is set to true, the collision rules defined by the project will take precedence, and the IgnoreLayers
property will not be visible or used.
Usage
To use the IgnoreLayers
property, you can set it to a TagSet
containing the tags of the layers you wish to ignore. This can be done programmatically within your game logic.
Example usage:
CharacterController characterController = new CharacterController();
characterController.IgnoreLayers = new TagSet { "Layer1", "Layer2" };
In this example, the character controller will ignore collisions with objects tagged as "Layer1" and "Layer2".
Example
CharacterController characterController = new CharacterController();
characterController.IgnoreLayers = new TagSet { "Layer1", "Layer2" };
// Check if the IgnoreLayers property is set correctly
if (characterController.IgnoreLayers.Contains("Layer1"))
{
// Logic for when Layer1 is ignored
}
// Toggle UseCollisionRules to see the effect on IgnoreLayers visibility
characterController.UseCollisionRules = true;
// Now IgnoreLayers will be hidden and not used in collision detection