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 andvec2(time * 32, 0)for horizontal scrolling. Pass the result to another Expression node'svecinput and read its components withx(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 theirvecinputlist_map/list_filter— reuse the result through the list expression'svecinputtime_source— supplies time (the expression's built-intimeis also available)
Read this first
- The
x,y,vec, andflagnames 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, andflagdirectly in the Inspector. - To use a variable from the Variables panel, retrieve it with
Variable Refor 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=0vec=[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
xto1 - Set
yto2 expression = vec2(x, y)
value = [1, 2]
Example 2: Add an offset
- Set
xto1 - Set
yto2 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.
&&/||andifshort-circuit. Reversedclampbounds are swapped,sign(0) = 0, and%is a non-negative Euclidean remainder. Division or modulo by zero andsqrtof a negative value produce an error.- While you type an expression, the incomplete intermediate text is evaluated immediately, so an error may appear temporarily.