GamepadAxis

Namespace:

namespace Lenga\Engine\Enumerations;

Identifies a physical axis on a gamepad controller. Use with Input::getAxis() to read analogue stick and trigger values.

Values

Case Value Description
LEFT_X 0 Left analogue stick, horizontal axis.
LEFT_Y 1 Left analogue stick, vertical axis.
RIGHT_X 2 Right analogue stick, horizontal axis.
RIGHT_Y 3 Right analogue stick, vertical axis.
LEFT_TRIGGER 4 Left trigger (LT / L2). Range 0–1.
RIGHT_TRIGGER 5 Right trigger (RT / R2). Range 0–1.

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Input;
use Lenga\Engine\Enumerations\GamepadAxis;

class GamepadMovement extends Behaviour
{
    public float $speed = 5.0;

    public function update(): void
    {
        $horizontal = Input::getAxis(GamepadAxis::LEFT_X->value);
        $vertical   = Input::getAxis(GamepadAxis::LEFT_Y->value);

        $this->transform->translate([
            $horizontal * $this->speed * Time::deltaTime(),
            0,
            $vertical   * $this->speed * Time::deltaTime(),
        ]);
    }
}