# Collision Detection and Events

The `Character` class includes numerous events that allow you to manage different character interactions. For instance, there is `OnCollided`, which is triggered when the character makes contact with a collider while executing a `Move`, `OnFoundGround`, which is triggered when a character detects any ground surface (whether **walkable** or **not-walkable**), among others.

When extending a `Character` class, it is advisable to override its corresponding event trigger method. For example, override the `OnCollided` method to handle a collision:

```csharp
public class PlayerCharacter : Character
{
    protected override void OnCollided(ref CollisionResult collisionResult)
    {
        // Call base method implementation
        
        base.OnCollided(ref collisionResult);
        
        // Add your code here...
        
        Debug.Log($"Collided with {collisionResult.collider.name}");
    }
}
```

On the other hand, when extending a `Character` through composition, it's advisable to listen to its exposed events. For example, subscribe to its `Collided` event to handle a collision:

```csharp
public class PlayerController : MonoBehaviour
{
    // The controlled Character

    private Character _character;

    protected void OnCollided(ref CollisionResult collisionResult)
    {
        Debug.Log($"Collided with {collisionResult.collider.name}");
    }

    private void OnEnable()
    {
        // Subscribe to Character events
        
        _character.Collided += OnCollided;
    }

    private void OnDisable()
    {
        // Un-subscribe from Character events
        
        _character.Collided -= OnCollided;
    }
}
```

The procedure is the same for its other events.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oscar-gracian.gitbook.io/easy-character-movement-2/walkthrough/collision-detection-and-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
