CapsuleCollider3D

Namespace:

namespace Lenga\Engine\Core;

class CapsuleCollider3D

Properties

  • radius: local capsule radius.
  • height: local capsule height.
  • offset: local offset from the GameObject transform.
  • isTrigger: detects overlap without producing a solid collision response.
  • materialPath: project-relative path to a Physics Material 3D asset.
  • material: a PhysicsMaterial3D object representing the collider material.

Methods

isTouching

public function isTouching(bool $includeTriggers = true, ?int $layerMask = null): bool

Returns true when this capsule collider is touching another matching 3D collider.

Set $includeTriggers to false to ignore trigger contacts. Pass a $layerMask to limit the check to colliders on matching GameObject layers.

getContacts

public function getContacts(bool $includeTriggers = true, ?int $layerMask = null): array

Returns the current Collision3D contacts involving this capsule collider.

Set $includeTriggers to false to return only solid contacts. Pass a $layerMask to limit results to matching GameObject layers.

moveAndSlide

public function moveAndSlide(
    Vector3 $delta,
    float $skinWidth = 0.05,
    bool $includeTriggers = false,
    ?int $layerMask = null,
): KinematicMove3DResult

Moves the GameObject by $delta using capsule collision and slides along blocking 3D colliders.

This method is deprecated for new character code. Prefer CharacterController::move() for kinematic movement.

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\CapsuleCollider3D;
use Lenga\Engine\Core\Debug;

class CharacterCollider extends Behaviour
{
    public function start(): void
    {
        $collider = $this->getComponent(CapsuleCollider3D::class);
        $collider->radius = 0.5;
        $collider->height = 2.0;
    }

    public function update(): void
    {
        $collider = $this->getComponent(CapsuleCollider3D::class);
        if ($collider->isTouching()) {
            Debug::log('Character is touching something');
        }
    }
}