Studio Yotsuba
Back to Node List

Expression Vec2

expression_vec2

Evaluates a small expression and outputs a vec2

Reviewed
Guide available

Input Ports

NameTypeDescription
X
x
Number
Number variable x
Y
y
Number
Number variable y
Vec
vec
Vec2
Optional vec2 variable
Flag
flag
Bool
Optional bool variable

Output Ports

NameTypeDescription
Value
value
Vec2
Vec2 result of the expression

Parameters

NameTypeDefaultRangeDescription / Options
X
x
Float
0-10000–10000 / step 0.01

Fallback value for x when the input pin is not connected

Y
y
Float
0-10000–10000 / step 0.01

Fallback value for y when the input pin is not connected

Vec X
vec_x
Float
0-10000–10000 / step 0.01

Fallback X component for vec when the vec input pin is not connected

Vec Y
vec_y
Float
0-10000–10000 / step 0.01

Fallback Y component for vec when the vec input pin is not connected

Flag
flag
Bool
false—

Fallback bool value when the flag input pin is not connected

Expression
expression
Text
vec2(x, y)—

Return a vec2. Examples: - vec2(x, y) - vec2(x + 1, y - 1) - vec + vec2(2, 0) Connected input pins override Inspector values.

Overview

Produces one 2D vector (Vec2) from a short expression. Its current main path is to reuse vector calculations through the vec input of another Expression node or of list_map / list_filter.

Usage tips

  • The go-to moving coordinates are vec2(sin(time*pi*2), cos(time*pi*2)) for circular motion and vec2(time * 32, 0) for horizontal scrolling. Pass the result to another Expression node's vec input and read its components with x(vec) / y(vec).
  • Round offsets to integers to keep pixel art stable: vec2(floor(x), floor(y)).
  • It is also useful simply to combine two numbers into a Vec2 (a number-to-Vec2 conversion point).

Related nodes

  • expression_float / expression_bool — reuse the result through their vec input
  • list_map / list_filter — reuse the result through the list expression's vec input
  • time_source — supplies time (the expression's built-in time is also available)

Read this first

  • The x, y, vec, and flag names here are separate from variables created in the Variables panel.
  • They are the input pin names of the Expression node itself.
  • You can also enter x, y, vec_x, vec_y, and flag directly in the Inspector.
  • To use a variable from the Variables panel, retrieve it with Variable Ref or a similar node and connect it to the relevant input pin.
  • When a value is connected to an input pin, the input-pin value takes precedence over the Inspector value.
  • Unconnected inputs use the following values:
    • x, y = 0
    • vec = [vec_x, vec_y]
    • flag = false

Available features

  • Variables: x, y, vec, vx, vy, flag, time, frame, total_frames
  • Operators: + - * / %, == != < <= > >=, && || !
  • Functions: min, max, clamp, abs, floor, ceil, round, sign, sin, cos, tan, sqrt, pow, lerp, vec2, x, y, length, if

Common expressions

  • vec2(x, y)
  • vec2(x + 1, y - 1)
  • vec + vec2(2, 0)
  • if(flag, vec2(1, 0), vec2(0, 1))

Concrete examples

Example 1: Convert coordinates directly to Vec2

  • Set x to 1
  • Set y to 2
  • expression = vec2(x, y)
value = [1, 2]

Example 2: Add an offset

  • Set x to 1
  • Set y to 2
  • expression = vec2(x + 1, y + 2)
value = [2, 4]

When to use it

  • When you want to reuse vector math across Expression or List expressions
  • When you want to keep two components together, then split them with x(vec) / y(vec) in a later expression

Notes

  • Make sure the expression can ultimately be converted to Vec2.
  • When unsure, explicitly writing vec2(...) is safest.
  • The primary Transform and Path nodes currently have no input that accepts Vec2 directly. Pass the components as separate numbers when needed.
  • && / || and if short-circuit. Reversed clamp bounds are swapped, sign(0) = 0, and % is a non-negative Euclidean remainder. Division or modulo by zero and sqrt of a negative value produce an error.
  • While you type an expression, the incomplete intermediate text is evaluated immediately, so an error may appear temporarily.
Back to Node List