CollisionFlags

Namespace:

namespace Lenga\Engine\Enumerations;

Describes which sides of a CharacterController were touching a collider after a move() call. The values are bit flags and can be combined.

Values

Case Value Description
None 0 No collision occurred.
Sides 1 The character is touching a collider on its sides (horizontal collision).
Above 2 The character's top is touching a collider (e.g. a ceiling).
Below 4 The character's bottom is touching a collider (e.g. the ground).

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\CharacterController;
use Lenga\Engine\Enumerations\CollisionFlags;

class PlatformerCharacter extends Behaviour
{
    private bool $isGrounded = false;

    public function update(): void
    {
        $cc = $this->getComponent(CharacterController::class);
        $flags = $cc->move([0, -9.8 * Time::deltaTime(), 0]);

        // Check if the character landed on the ground
        $this->isGrounded = (bool)($flags->value & CollisionFlags::Below->value);
    }
}