Input System

Overview

The Input system provides frame-aware input tracking for both the editor and gameplay scripts.

Editor Camera Controls

The editor viewport uses the following controls:

ActionInput
Fly modeRight-click + WASD + QE (up/down) + mouse look
SprintHold Shift during fly mode
OrbitAlt + Left-click drag
Orbit zoomAlt + Right-click drag
PanMiddle-click drag
Scroll zoomScroll wheel
Focus selectionF key (focuses on selected entity)

Gameplay Input via C++ Behaviors

For gameplay input, use the Input class accessible via engine.GetInput() in Behavior subclasses. The following methods are available:

FunctionDescription
IsKeyDown(key)Key is held this frame
IsKeyPressed(key)Key was just pressed (transition)

Key Constants

Available key constants (from GLFW):

KEY_W, KEY_A, KEY_S, KEY_D, KEY_SPACE, KEY_ESCAPE

Example

void OnUpdate(flecs::entity e, Engine &engine, float dt) override {
    auto &input = engine.GetInput();
    float speed = 5.0f;
    float vx = 0.0f, vz = 0.0f;
    if (input.IsKeyDown(GLFW_KEY_W)) vz -= speed;
    if (input.IsKeyDown(GLFW_KEY_S)) vz += speed;
    if (input.IsKeyDown(GLFW_KEY_A)) vx -= speed;
    if (input.IsKeyDown(GLFW_KEY_D)) vx += speed;
    engine.GetPhysicsWorld().SetLinearVelocity(e.id(), vx, 0.0f, vz);
}

Integration Notes

  • Input state is updated automatically each frame in Engine::BeginFrame()
  • GLFW callbacks feed into Input state and publish events to the EventBus
  • The editor camera consumes input directly; gameplay input is accessed through engine.GetInput() in C++ behaviors