Description
The Defaults
property of the CollisionRules
class provides a dictionary that defines the default collision rules for physics interactions. If no specific pair matching is found in the Pairs
dictionary, the rules specified in Defaults
will be used. This property is essential for ensuring that there is always a fallback rule for any collision scenario that is not explicitly defined.
Usage
To use the Defaults
property, you can access it directly from an instance of the CollisionRules
class. You can add, remove, or modify the default collision rules by manipulating the dictionary entries. Each entry in the dictionary uses a string as the key, representing a tag, and a CollisionRules.Result
as the value, which defines the outcome of the collision.
Example
// Example of accessing and modifying the Defaults property
var collisionRules = new CollisionRules();
// Add a default collision rule
collisionRules.Defaults["Player"] = CollisionRules.Result.Ignore;
// Modify an existing default collision rule
collisionRules.Defaults["Enemy"] = CollisionRules.Result.Block;
// Remove a default collision rule
collisionRules.Defaults.Remove("Projectile");
// Iterate over all default rules
foreach (var rule in collisionRules.Defaults)
{
Console.WriteLine($"Tag: {rule.Key}, Result: {rule.Value}");
}