GML Lengthdir Visualizer

See exactly where lengthdir_x / lengthdir_y lands — click, drag, get GameMaker code
by GanjaViruss & Claude Opus 4.8 & Sonnet 4.6
✦ Built with AI
Drag origin (white cross) onto your pivot · tap empty = new point · Shift+tap = child point · drag points to move · drag empty / middle-mouse = pan · wheel / pinch = zoom

Sprite & view

3.0×

Active point

lengthdir_x 0 lengthdir_y 0

Points

Output options

object position
your facing/angle variable — added to each point's direction

Generated GML

How lengthdir works

lengthdir_x(len, dir) and lengthdir_y(len, dir) answer one question: "if I walk len pixels in direction dir, how far do I move on X and Y?"

Direction in GameMaker: = right, 90° = up, 180° = left, 270° = down. It goes counter-clockwise (because screen Y points down).

Typical use: placing something offset from an object — a gun muzzle, a held item, a light source, an orbit point:

var _muzzle_x = x + lengthdir_x(48, image_angle);
var _muzzle_y = y + lengthdir_y(48, image_angle);

Rotate with image_angle: if the offset should turn with your object (like a gun barrel), enable that option — it adds image_angle to the direction so the point follows your sprite's rotation.

Collision boxes & lines that rotate

Set a point's type to Line (in the active-point panel) and pick an Output of collision_line or collision_rectangle. Each line point becomes a segment from its base (origin or parent point) to its tip.

Why this is powerful: a rotating collision box (car doors, swinging hitboxes, turret arcs) normally forces you to hard-code a separate version for each angle. With image_angle added to the direction, one set of points works for every angle — no more if image_angle == 0 / 90 / 180 / 270 blocks.

Tip: make a Point for the hinge/anchor (offset from the object), then Shift+click to add a Line child — that child is the swinging segment. Use draw_line output first to see your boxes in-game, then switch to collision_line.