KinematicMove3DResult

Namespace:

namespace Lenga\Engine\Core;

class KinematicMove3DResult

Example

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

class CharacterMovement extends Behaviour
{
    public function update(): void
    {
        $controller = $this->getComponent(CharacterController::class);

        // Move the character
        $moveDirection = new Vector3(1, 0, 0);
        $result = $controller->move($moveDirection);

        // Check the move result
        if ($result->collided) {
            Debug::log('Character hit something');

            if ($result->hit !== null) {
                $hitObject = $result->hit->gameObject;
                $hitDistance = $result->hit->distance;
                Debug::log('Hit object: ' . $hitObject->name);
            }
        }

        if ($result->usedSlide) {
            Debug::log('Character slid along a surface');
        }
    }
}