# Step 2 - Move The Hero

> Drive the Babylon Bros hero left and right with keyboard events, a velocity variable, and a per-frame physics update in the Flow Graph Editor.

Source: https://doc.babylonjs.com/toolsAndResources/flowGraphEditor/babylonBrosTutorial/movement

## Goal

Make the hero run left and right with the arrow keys. The pattern is: keyboard events set a direction variable, and a per-frame tick converts that direction into physics velocity.

Open this step in the editor: [#1CUUOO](https://flowgraph.babylonjs.com/#1CUUOO) (load scene `P41T6E#2` in the preview).

![Movement graph: keyboard input and a per-frame velocity update](https://doc.babylonjs.com/img/tools/flowGraphEditor/tutorial/movement.webp)

Run this step:

- [Playground: Babylon Bros - Move](https://playground.babylonjs.com/#LKYK2H#0) - Tutorial step: drive the hero left and right with the arrow keys, powered by flow graph #1CUUOO.

## Blocks Used

- `KeyDownEvent`, `KeyUpEvent` (Events)
- `SetVariable`, `GetVariable` (Data Access)
- `SceneTickEvent` (Events)
- `GetProperty` / `SetLinearVelocity` (Data Access / Physics)
- `Multiply`, `CombineVector3` (Math / Data Conversion)

## Step By Step

### 1. Initialize State

Add `SceneReadyEvent` and a `SetVariable` named `heroVX = 0`. This sets the starting horizontal direction once the scene is ready. Use the property panel to set the variable type to number.

### 2. Read The Keys

Add two `KeyDownEvent` blocks. Configure one for `ArrowRight` and one for `ArrowLeft` in the property panel. Wire each into a `SetVariable` that sets `heroVX` to `1` and `-1`. Add two `KeyUpEvent` blocks that reset `heroVX` to `0`.

Use a sticky note (`Ctrl/Cmd+M`) to label this cluster "Input".

### 3. Apply Velocity Each Frame

Add `SceneTickEvent`. Read `heroVX` with `GetVariable`, multiply it by a speed `Constant`, and build a velocity vector with `CombineVector3` (x = heroVX*speed, y = current vy, z = 0). Feed it into `SetLinearVelocity` targeting the `hero` physics body, selected from the scene picker.

### 4. Group It

Select the tick blocks and press `Ctrl/Cmd+G` to make a smart group. This keeps the canvas readable as later steps add more.

## Test In The Editor

Press Start and use the arrow keys in the preview. The hero should run. Turn on Debug Mode to watch the tick blocks light up each frame, and inspect `heroVX` in the Variables panel as you press keys.

## Save

Save to the snippet server. Your graph should match `#1CUUOO`. Continue with [Step 3 - Add Jumping](https://doc.babylonjs.com/toolsAndResources/flowGraphEditor/babylonBrosTutorial/jump).

## Further reading

- [Step 1 - Set Up The Editor](https://doc.babylonjs.com/toolsAndResources/flowGraphEditor/babylonBrosTutorial/setup)
- [Step 3 - Add Jumping](https://doc.babylonjs.com/toolsAndResources/flowGraphEditor/babylonBrosTutorial/jump)
- [Control Flow Blocks](https://doc.babylonjs.com/toolsAndResources/flowGraphEditor/controlFlowBlocks)
