Physics3D

Namespace:

namespace Lenga\Engine\Core;

class Physics3D

Methods

moveAndSlideSphere

public static function moveAndSlideSphere(Vector3 $position,
        float $radius,
        Vector3 $delta,
        ?GameObject $ignoreGameObject = null,
        ?Vector3 $offset = null,
        float $skinWidth = 0.05,
        bool $includeTriggers = false,
        ?int $layerMask = null,)

@deprecated Use CharacterController::move() for the current kinematic movement workflow.

moveAndSlideCapsule

public static function moveAndSlideCapsule(Vector3 $position,
        float $radius,
        float $height,
        Vector3 $delta,
        ?GameObject $ignoreGameObject = null,
        ?Vector3 $offset = null,
        float $skinWidth = 0.05,
        bool $includeTriggers = false,
        ?int $layerMask = null,)

@deprecated Use CharacterController::move() for the current kinematic movement workflow.

layerMask

public static function layerMask(int ...$layers)

raycast

public static function raycast(Vector3 $origin,
        Vector3 $direction,
        float $distance,
        bool $includeTriggers = true,
        ?int $layerMask = null,)

raycastAll

public static function raycastAll(Vector3 $origin,
        Vector3 $direction,
        float $distance,
        bool $includeTriggers = true,
        ?int $layerMask = null,)

@return list

overlapSphereAll

public static function overlapSphereAll(Vector3 $center,
        float $radius,
        bool $includeTriggers = true,
        ?int $layerMask = null,)

@return list

overlapBoxAll

public static function overlapBoxAll(Vector3 $center,
        Vector3 $size,
        bool $includeTriggers = true,
        ?int $layerMask = null,)

@return list

overlapCapsuleAll

public static function overlapCapsuleAll(Vector3 $center,
        float $radius,
        float $height,
        bool $includeTriggers = true,
        ?int $layerMask = null,)

@return list

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Debug;
use Lenga\Engine\Core\Physics3D;
use Lenga\Engine\Core\Vector3;

class PhysicsQueries3D extends Behaviour
{
    public function update(): void
    {
        // Raycast in 3D
        $origin = $this->transform->position;
        $direction = $this->transform->forward;
        $hit = Physics3D::raycast($origin, $direction, 100.0);

        if ($hit !== null) {
            Debug::log('Raycast hit: ' . $hit->gameObject->name);
            Debug::log('Distance: ' . $hit->distance);
        }

        // Overlap sphere
        $sphereColliders = Physics3D::overlapSphereAll(
            new Vector3(0, 1, 0),
            5.0
        );
        Debug::log('Objects in sphere: ' . count($sphereColliders));

        // Overlap box
        $boxColliders = Physics3D::overlapBoxAll(
            new Vector3(0, 0, 0),
            new Vector3(2, 2, 2)
        );
        Debug::log('Objects in box: ' . count($boxColliders));
    }
}