RaycastHit3D

Namespace:

namespace Lenga\Engine\Core;

class RaycastHit3D

Methods

fromNativeData

public static function fromNativeData(array $data)

Example

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

class WeaponRaycast extends Behaviour
{
    public function update(): void
    {
        if (Input::getMouseButtonDown(0)) {
            // Cast a ray from camera forward
            $camera = $this->getComponent(Camera::class);
            $origin = $camera->transform->position;
            $direction = $camera->transform->forward;

            // Raycast from camera
            $hit = Physics3D::raycast($origin, $direction, 1000.0);

            if ($hit !== null) {
                $targetObject = $hit->gameObject;
                $impactPoint = $hit->point;

                Debug::log('Shot ' . $targetObject->name);
                // Apply damage, create impact effect, etc.
            }
        }
    }
}