BoxCollider3D

Namespace:

namespace Lenga\Engine\Core;

class BoxCollider3D

Properties

  • size: the local box size.
  • 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 box 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 box collider.

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

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\BoxCollider3D;
use Lenga\Engine\Core\Collision3D;
use Lenga\Engine\Core\Debug;
use Lenga\Engine\Core\PhysicsMaterial3D;
use Lenga\Engine\Core\Vector3;

class TriggerZone extends Behaviour
{
    public function start(): void
    {
        $collider = $this->getComponent(BoxCollider3D::class);
        $collider->size = new Vector3(2.0, 2.0, 2.0);
        $collider->isTrigger = true;
        $collider->material = new PhysicsMaterial3D(staticFriction: 0.9);
    }

    public function onTriggerEnter(Collision3D $collision): void
    {
        Debug::log('Entered trigger zone');
    }
}