Tutorial: Meadow Quest (2D RPG)
4. Move the hero
Your first 2D visual script. Read the Move action (WASD, arrows, gamepad) and turn it into the hero's velocity.
The idea
Every frame: read the Move input as a direction, multiply it by a speed, and use it as the hero's velocity. The physics engine then moves the hero, and stops it at walls.
OnUpdate ──▶ SetVelocity2D( MakeVec2( x , y ) )
x, y = Vec3X / Vec3Y of ScaleVec3( ActionVector2 "Move" , 5 )Move is a built-in input action. Out of the box it is bound to W A S D, the arrow keys and a gamepad's left stick. You can see and change the bindings in Windows > Input Actions.
Build it
- Windows > Script Editor, then + New. Type
HeroMoveand press Create. - The new script starts with a demo graph made for 3D objects. Click each node except OnUpdate and press Delete.
- Add nodes: hover over an empty part of the canvas, press Space, type part of the name, and press Enter. The node appears under the mouse. Add: ActionVector2, ConstNumber, ScaleVec3, Vec3X, Vec3Y, MakeVec2, SetVelocity2D.
- Click the ConstNumber node. The strip above the canvas shows its value; set it to
5(the speed). ActionVector2 already saysaction = Move. - Wire it by dragging from an output pin (right side of a node) to an input pin (left side):
- OnUpdate's white exec pin → SetVelocity2D's exec input
- ActionVector2 → ScaleVec3
v; ConstNumber → ScaleVec3s - ScaleVec3 → Vec3X and → Vec3Y
- Vec3X → MakeVec2
x; Vec3Y → MakeVec2y - MakeVec2 → SetVelocity2D
value
- Compile. The status should read compiles (1 handler). Then Save.

If something is missing, the editor says so plainly. For example, an action that isn't connected to an event reads "sits in an exec chain no event handler reaches… wire it to OnStart or OnUpdate".
…or paste the text
Switch to the Text tab, select everything, and paste. The graph rebuilds itself:
//!tgscript v1
//! script name=HeroMove
//! region graph
//! node 1 OnUpdate pos=(60,80)
export function onUpdate(ctx) {
//! node 2 ActionVector2 pos=(260,80) action=Move
const n2_value = ctx.actionVector2("Move");
//! node 3 ConstNumber pos=(260,200)
const n3_value = 5.00;
//! node 4 ScaleVec3 pos=(460,120)
const n4_out = ctx.scaleVec3(n2_value, n3_value);
//! node 5 Vec3X pos=(660,80)
const n5_out = ctx.vec3X(n4_out);
//! node 6 Vec3Y pos=(660,200)
const n6_out = ctx.vec3Y(n4_out);
//! node 7 MakeVec2 pos=(860,120)
const n7_out = ctx.makeVec2(n5_out, n6_out);
//! node 8 SetVelocity2D pos=(1060,120)
ctx.setVelocity2D(n7_out);
}
//! endregionAttach and play
- Select Hero. In the Inspector's Script section, click the slot that reads (none)
and pick
HeroMove.tgscript. - ▶ Play, click into the Simulation panel, and walk with W A S D. The hero moves at 5 units per second and stops when you let go.
- ■ Stop puts the hero back where it started.
In our test, holding D for about a second moved the hero 4.6 units right, and it didn't drift down. That's the zero gravity scale from Part 3 doing its job.
Good practices
- Keep tuning numbers in one node. The speed lives in a single ConstNumber; change it there and nothing else. Name things so a graph reads left to right: input → maths → action.
- Drive physics bodies with velocity, not position. Setting the velocity lets the physics engine stop the hero at walls. Setting the position teleports it through them.
- Read actions, not keys. Move already covers WASD, the arrows and a gamepad, and the bindings can change in Windows > Input Actions without touching the script.
- Compile often. The status line names the node that's wrong, in plain words.
This part's assets
HeroMove.tgscript. The download is the final version from Part 8, which also waits for the title screen; the text above is this part's version.