Formulas

This article describes the examples of formulas you can use in Animation mode to set up custom behaviors.

Functions

Syntax

Description

Use Examples

`random(YOUR_MAX_VALUE)`

Random integer in the range from 0 to YOUR_MAX_VALUE

`random(234)`

`random(YOUR_MIN_VALUE, YOUR_MAX_VALUE)`

Random integer in the range from YOUR_MIN_VALUE to YOUR_MAX_VALUE

`random(1, 100)`

`getLocalPositionX('YOUR OBJECT NAME')`

Local X-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`getLocalPositionX('car') + 1`

`getGlobalPositionX('YOUR OBJECT NAME')`

Global X-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`getGlobalPositionX('car') + 1`

`getLocalPositionY('YOUR OBJECT NAME')`

Local Y-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`a + getLocalPositionY('airplane') * 2`

`getGlobalPositionY('YOUR OBJECT NAME')`

Global Y-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`a + getGlobalPositionY('airplane') * 2`

`getLocalPositionZ('YOUR OBJECT NAME')`

Local Z-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`getLocalPositionZ('My Object') - 5`

`getGlobalPositionZ('YOUR OBJECT NAME')`

Global Z-coordinate of the first object that comes across in the scene with the name YOUR OBJECT NAME

`getGlobalPositionZ('My Object') - 5`

`getLocalRotationX('YOUR OBJECT NAME')`

Local X-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getLocalRotationX('Plane')`

`getGlobalRotationX('YOUR OBJECT NAME')`

Global X-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getGlobalRotationX('Plane')`

`getLocalRotationY('YOUR OBJECT NAME')`

Local Y-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getLocalRotationY('Plane')`

`getGlobalRotationY('YOUR OBJECT NAME')`

Global Y-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getGlobalRotationY('Plane')`

`getLocalRotationZ('YOUR OBJECT NAME')`

Local Z-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getLocalRotationZ('Plane')`

`getGlobalRotationZ('YOUR OBJECT NAME')`

Global Z-angle in degrees of the first object on the scene named YOUR OBJECT NAME

`getGlobalRotationZ('Plane')`

`getGlobalSizeInMetersX('YOUR OBJECT NAME')`

Returns the X-size of a physical body in meters. The global AABB (axis aligned bounding box) is used

`getGlobalSizeInMetersX('Phys Mesh')`

`getGlobalSizeInMetersY('YOUR OBJECT NAME')`

Returns the Y-size of a physical body in meters. The global AABB (axis aligned bounding box) is used

`getGlobalSizeInMetersY('Phys Mesh')`

`getGlobalSizeInMetersZ('YOUR OBJECT NAME')`

Returns the Z-size of a physical body in meters. The global AABB (axis aligned bounding box) is used

`getGlobalSizeInMetersZ('Phys Mesh')`

`getViewportWidth()`

Returns width of viewport in pixels

`getViewportWidth()`

`getViewportHeight()`

Returns height of viewport in pixels

`getViewportHeight()`

System Variables

Name

Description

Use Examples

`origin`

The value assigned to the previous keyframe. In the first keyframe, it is equal to the value from the scene.

`origin+10`

`iterator`

The number in the order of the keyframe in the clip to which this keyframe belongs. The countdown starts from 0.

`cos(2*pi*iterator/(amount-1))*10`

`amount`

The number of keyframes in the animation track that this keyframe belongs to.

`sin(2*pi*iterator/(amount-1))*10`

`pi`

Pi number

`2piR`

Object Variables

Syntax

Description

Use Examples

`${object name}.variableName`

User's custom variable

`${My character}.countOfCollectedCoins`

`Letters`

, `numbers`

, `symbols`

`_`

`-`

Variables created within a certain animation timeline that are applied to it only.

`Var2*25`

, `SomeUsersVar-5 `

, `randomDistance`

Operations and Functions

Arithmetic and Assignment Operators

Operator

Definition

Use Examples

`+`

Addition between x and y.

`x + y`

`-`

Subtraction between x and y.

`x - y`

`*`

Multiplication between x and y.

`x * y`

`/`

Division between x and y.

`x / y`

`%`

Modulus of x with respect to y.

`x % y`

`^`

x to the power of y.

`x ^ y`

`:=`

Assign the value of x to y. Where y is either a variable or vector type.

`y := x`

`+=`

Increment x by the value of the expression on the right-hand side. Where x is either a variable or vector type.

`x += abs(y - z)`

`-=`

Decrement x by the value of the expression on the right-hand side. Where x is either a variable or vector type.

`x[i] -= abs(y + z)`

`*=`

Assign the multiplication of x by the value of the expression on the righthand side to x. Where x is either a variable or vector type.

`x *= abs(y / z)`

`/=`

Assign the division of x by the value of the expression on the right-hand side to x. Where x is either a variable or vector type.

`x[i + j] /= abs(y * z)`

`%=`

Assign x modulo the value of the expression on the right| | | hand side to x. Where x is either a variable or vector type.

`x[2] %= y ^ 2`

Equalities and Inequalities

Operator

Definition

Use Examples

`==`

or `=`

True only if x is strictly equal to y.

`x == y`

`<>`

or `!=`

True only if x does not equal y.

`x <> y`

or `x != y`

`<`

True only if x is less than y.

`x < y`

`<=`

True only if x is less than or equal to y.

`x <= y`

`>`

True only if x is greater than y.

`x > y`

`>=`

True only if x greater than or equal to y.

`x >= y`

Boolean Operations

Operator

Definition

Use Examples

`true`

True state or any value other than zero (typically 1).

â€‹

`false`

False state, value of exactly zero.

â€‹

`and`

Logical AND, True only if x and y are both true.

`x and y`

`mand`

Multi-input logical AND, True only if all inputs are true. Left to right short-circuiting of expressions.

`mand(x > y, z < w, u or v, w and x)`

`mor`

Multi-input logical OR, True if at least one of the inputs are true. Left to right short-circuiting of expressions.

`mor(x > y, z < w, u or v, w and x)`

`nand`

Logical NAND, True only if either x or y is false.

`x nand y`

`nor`

Logical NOR, True only if the result of x or y is false.

`x nor y`

`not`

Logical NOT, Negate the logical sense of the input.

`not(x and y) == x nand y`

`or`

Logical OR, True if either x or y is true.

`x or y`

`xor`

Logical XOR, True only if the logical states of x and y differ.

`x xor y`

`xnor`

Logical XNOR, True iff the biconditional of x and y is satisfied.

`x xnor y`

`&`

Similar to AND but with left to right expression short circuiting optimization.

`(x & y) == (y and x)`

`|`

Similar to OR but with left to right expression short circuiting optimization.

`(x | y) == (y or x)`

General Purpose Functions

Function

Definition

Use Examples

`abs`

Absolute value of x.

`abs(x)`

`avg`

Average of all the inputs.

`avg(x,y,z,w,u,v) == (x + y + z + w + u + v) / 6`

`ceil`

Smallest integer that is greater than or equal to x.

â€‹

`clamp`

Clamp x in range between r0 and r1, where r0 < r1.

`clamp(r0,x,r1)`

`equal`

Equality test between x and y using normalized epsilon.

â€‹

`erf`

Error function of x.

`erf(x)`

`erfc`

Complimentary error function of x.

`erfc(x)`

`exp`

e to the power of x.

`exp(x)`

`expm1`

e to the power of x minus 1, where x is very small.

`expm1(x)`

`floor`

Largest integer that is less than or equal to x.

`floor(x)`

`frac`

Fractional portion of x.

`frac(x)`

`hypot`

Hypotenuse of x and y.

`hypot(x,y) = sqrt(x*x + y*y)`

`iclamp`

Inverse-clamp x outside of the range r0 and r1. Where r0 < r1. If x is within the range it will snap to the closest bound.

`iclamp(r0,x,r1)`

`inrange`

In-range returns 'true' when x is within the range r0 and r1. Where r0 < r1.

`inrange(r0,x,r1)`

`log`

Natural logarithm of x.

`log(x)`

`log10`

Base 10 logarithm of x.

`log10(x)`

`log1p`

Natural logarithm of 1 + x, where x is very small.

`log1p(x)`

`log2`

Base 2 logarithm of x.

`log2(x)`

`logn`

Base N logarithm of x. where n is a positive integer.

`logn(x,8)`

`max`

Largest value of all the inputs.

`max(x,y,z,w,u,v)`

`min`

Smallest value of all the inputs.

`min(x,y,z,w,u)`

`mul`

Product of all the inputs.

`mul(x,y,z,w,u,v,t) == (x*y*z*w*u*v*t)`

`ncdf`

Normal cumulative distribution function.

`ncdf(x)`

`nequal`

Not-equal test between x and y using normalized epsilon.

â€‹

`pow`

x to the power of y.

`pow(x,y) == x ^ y`

`root`

Nth-Root of x. where n is a positive integer.

`root(x,3) == x^(1/3)`

`round`

Round x to the nearest integer.

`round(x)`

`roundn`

Round x to n decimal places where n > 0 and is an integer.

`roundn(x,3) roundn(1.2345678,4) == 1.2346`

`sgn`

Sign of x, -1 where x < 0, +1 where x > 0, else zero.

`sgn(x)`

`sqrt`

Square root of x, where x >= 0.

`sqrt(x)`

`sum`

Sum of all the inputs.

`sum(x,y,z,w,u,v,t) == (x + y + z + w + u + v + t)`

`swap <=>`

Swap the values of the variables x and y and return the current value of y.

`swap(x,y) or x <=> y`

`trunc`

Integer portion of x.

`trunc(x)`

Trigonometry Functions

Function

Definition

Use Examples

`acos`

Arc cosine of x expressed in radians. Interval [-1,+1]

`acos(x)`

`acosh`

Inverse hyperbolic cosine of x expressed in radians.

`acosh(x)`

`asin`

Arc sine of x expressed in radians. Interval [-1,+1]

`asin(x)`

`asinh`

Inverse hyperbolic sine of x expressed in radians.

`asinh(x)`

`atan`

Arc tangent of x expressed in radians. Interval [-1,+1]

`atan(x)`

`atan2`

Arc tangent of (x / y) expressed in radians. [-pi,+pi]

`atan2(x,y)`

`atanh`

Inverse hyperbolic tangent of x expressed in radians.

`atanh(x)`

`cos`

Cosine of x.

`cos(x)`

`cosh`

Hyperbolic cosine of x.

`cosh(x)`

`cot`

Cotangent of x.

`cot(x)`

`csc`

Cosecant of x.

`csc(x)`

`sec`

Secant of x.

`sec(x)`

`sin`

Sine of x.

`sin(x)`

`sinc`

Sine cardinal of x.

`sinc(x)`

`sinh`

Hyperbolic sine of x.

`sinh(x)`

`tan`

Tangent of x.

`tan(x)`

`tanh`

Hyperbolic tangent of x.

`tanh(x)`

`deg2rad`

Convert x from degrees to radians.

`deg2rad(x)`

`deg2grad`

Convert x from degrees to gradians.

`deg2grad(x)`

`rad2deg`

Convert x from radians to degrees.

`rad2deg(x)`

`grad2deg`

Convert x from gradians to degrees.

`grad2deg(x)`

String Processing

Function

Definition

Use Examples

`=`

, `==`

, `!=`

, `<>`

, `<=`

, `>=`

, `>`

, `<`

All common equality/inequality operators are applicable to strings and are applied in a case sensitive manner. In the following example x, y and z are of type string.

`not((x <= 'AbC') and ('1x2y3z' <> y)) or (z == x)`

`in`

True only if x is a substring of y.

`x in y or 'abc' in 'abcdefgh'`

`like`

True only if the string x matches the pattern y. Available wildcard characters are '*' and '?' denoting zero or more and zero or one matches respectively.

`x like y or 'abcdefgh' like 'a?d*h'`

`ilike`

True only if the string x matches the pattern y in a case insensitive manner. Available wildcard characters are '*' and '?' denoting zero or more and zero or one matches respectively.

`x ilike y or 'a1B2c3D4e5F6g7H' ilike 'a?d*h'`

`[r0:r1]`

The closed interval

`[r0,r1]`

of the specified string. Given a string x with a value of 'abcdefgh' then (see example). Note: Both r0 and r1 are assumed to be integers, where r0 <= r1. They may also be the result of an expression, in the event they have fractional components truncation will be performed. (eg: 1.67 --> 1)

`x[1:4] == 'bcde'`

`x[ :5] == x[:10 / 2] == 'abcdef'`

`x[2 + 1: ] == x[3:] =='defgh' `

`x[ : ] == x[:] == 'abcdefgh' `

`x[4/2:3+2] == x[2:5] == 'cdef'`

`:=`

Assign the value of x to y. Where y is a mutable string or string range and x is either a string or a string range.

â€‹

Note: For options 7 and 8 the shorter of the two ranges will denote the number of characters that are to be copied.

`y := x`

`y := 'abc'`

`y := x[:i + j]`

`y := '0123456789'[2:7]`

`y := '0123456789'[2i + 1:7]`

`y := (x := '0123456789'[2:7]) `

`y[i:j] := x`

`y[i:j] := (x + 'abcdefg'[8 / 4:5])[m:n] `

`+`

Concatenation of x and y. Where x and y are strings or string ranges.

`x + y`

`x + 'abc'`

`x + y[:i + j]`

`x[i:j] + y[2:3] + '0123456789'[2:7]`

`'abc' + x + y | | | 6. 'abc' + '1234567'`

`(x + 'a1B2c3D4' + y)[i:2j]`

`+=`

Append to x the value of y. Where x is a mutable string and y is either a string or a string range.

`x += y `

`x += 'abc' `

`x += y[:i + j] + 'abc' `

`x += '0123456789'[2:7]`

`<=>`

Swap the values of x and y. Where x and y are mutable strings.

`x <=> y`

`[]`

The string size operator returns the size of the string being actioned.

`'abc'[] == 3`

`var max_str_length := max(s0[],s1[],s2[],s3[])`

`('abc' + 'xyz')[] == 6`

`(('abc' + 'xyz')[1:4])[] == 4`

Control Structures

Structure

Definition

Use Examples

`if`

If x is true then return y else return z.

`if (x, y, z) `

`if ((x + 1) > 2y, z + 1, w / v) `

`if (x > y) z; `

`if (x <= 2*y) { z + w };`

`if-else`

The if-else/else-if statement. Subject to the condition branch the statement will return either the value of the consequent or the alternative branch.

`if (x > y) z; else w; `

`if (x > y) z; else if (w != u) v; `

`if (x < y) { z; w + 1; } else u; `

`if ((x != y) and (z > w)) `

`{ `

`y := sin(x) / u; `

`z := w + 1; `

`}`

`else if (x > (z + 1))`

`{ `

`w := abs (x - y) + z; `

`u := (x + 1) > 2y ? 2u : 3u; `

`}`

`switch`

The first true case condition that is encountered will determine the result of the switch. If none of the case conditions hold true, the default action is assumed as the final return value. This is sometimes also known as a multi-way branch mechanism.

`switch `

`{`

`ase x > (y + z) : 2 * x / abs(y - z); `

`case x < 3 : sin(x + y); `

`default : 1 + x; `

`}`

`while`

The structure will repeatedly evaluate the internal statement(s) 'while' the condition is true. The final statement in the final iteration will be used as the return value of the loop.

`while ((x -= 1) > 0) `

`{ `

`y := x + z; `

`w := u + y; `

`}`

`repeat/until`

The structure will repeatedly evaluate the internal until statement(s) 'until' the condition is true. The final statement in the final iteration will be used as the return value of the loop.

`repeat `

`y := x + z; `

`w := u + y; `

`until ((x += 1) > 100)`

`for`

The structure will repeatedly evaluate the internal statement(s) while the condition is true. On each loop iteration, an 'incrementing' expression is evaluated. The conditional is mandatory whereas the initializer and incrementing expressions are optional.

`for (var x := 0; (x < n) and (x != y); x += 1) `

`{ `

`y := y + x / 2 - z; `

`w := u + y; `

`}`

`break break[]`

Break terminates the execution of the nearest enclosed loop, allowing for the execution to continue on external to the loop. The default break statement will set the return value of the loop to NaN, where as the return based form will set the value to that of the break expression.

`while ((i += 1) < 10) `

`{ `

`if (i < 5) `

` j -= i + 2; `

`else if (i % 2 == 0) `

`break;`

`else | | | break[2i + 3]; `

`}`

`continue`

Continue results in the remaining portion of the nearest enclosing loop body to be skipped.

`for (var i := 0; i < 10; i += 1) `

`{ `

`if (i < 5) `

`continue; `

`j -= i + 2; `

`}`

`return`

Return immediately from within the current expression. With the option of passing back a variable number of values (scalar, vector or string).

`return [1]; `

`return [x, 'abx']; `

`return [x, x + y,'abx']; `

`return []; `

`if (x < y) `

`return [x, x - y, 'result-set1', 123.456];`

`else `

`return [y, x + y, 'result-set2'];`

`?:`

Ternary conditional statement, similar to that of the above denoted if-statement.

`x ? y : z `

`x + 1 > 2y ? z + 1 : (w / v) `

`min(x,y) > z ? (x < y + 1) ? x : y : (w * v)`

`~`

Evaluate each sub-expression, then return as the result the value of the last sub-expression. This is sometimes known as multiple sequence point evaluation.

`~(i := x + 1, j := y / z, k := sin(w/u)) == (sin(w/u))) `

`~{i := x + 1; j := y / z; k := sin(w/u)} == (sin(w/u)))`

`[*]`

Evaluate any consequent for which its case statement is true. The return value will be either zero or the result of the last consequent to have been evaluated.

`[*]`

`{ `

`case (x + 1) > (y - 2) : x := z / 2 + sin(y / pi); `

`case (x + 2) < abs(y + 3) : w / 4 + min(5y,9); `

`case (x + 3) == (y * 4) : y := abs(z / 6) + 7y; `

`}`

`[]`

The vector size operator returns the size of the vector being actioned.

`v[] `

`max_size := max(v0[],v1[],v2[],v3[])`

â€‹

Last modified 6mo ago