Skip to content

Curve

Inherits: Resource < RefCounted < Object

A mathematical curve.

This resource describes a mathematical curve by defining a set of points and tangents at each point. By default, it ranges between 0 and 1 on the X and Y axes, but these ranges can be changed.

Please note that many resources and nodes assume they are given unit curves. A unit curve is a curve whose domain (the X axis) is between 0 and 1. Some examples of unit curve usage are CPUParticles2D.angle_curve and Line2D.width_curve.

Type Name Default
int bake_resolution 100
float max_domain 1.0
float max_value 1.0
float min_domain 0.0
float min_value 0.0
int point_count 0
int point_{index}/left_mode 0
float point_{index}/left_tangent 0.0
Vector2 point_{index}/position Vector2(0, 0)
int point_{index}/right_mode 0
float point_{index}/right_tangent 0.0
Returns Method
int add_point(position: Vector2, left_tangent: float = 0, right_tangent: float = 0, left_mode: TangentMode = 0, right_mode: TangentMode = 0)
void bake()
void clean_dupes()
void clear_points()
float get_domain_range() const
TangentMode get_point_left_mode(index: int) const
float get_point_left_tangent(index: int) const
Vector2 get_point_position(index: int) const
TangentMode get_point_right_mode(index: int) const
float get_point_right_tangent(index: int) const
float get_value_range() const
void remove_point(index: int)
float sample(offset: float) const
float sample_baked(offset: float) const
void set_point_left_mode(index: int, mode: TangentMode)
void set_point_left_tangent(index: int, tangent: float)
int set_point_offset(index: int, offset: float)
void set_point_right_mode(index: int, mode: TangentMode)
void set_point_right_tangent(index: int, tangent: float)
void set_point_value(index: int, y: float)

domain_changed

domain_changed()

Emitted when max_domain or min_domain is changed.

range_changed

range_changed()

Emitted when max_value or min_value is changed.

TangentMode

enum TangentMode

TANGENT_FREE = 0

The tangent on this side of the point is user-defined.

TANGENT_LINEAR = 1

The curve calculates the tangent on this side of the point as the slope halfway towards the adjacent point.

TANGENT_MODE_COUNT = 2

The total number of available tangent modes.

bake_resolution

int bake_resolution = 100

The number of points to include in the baked (i.e. cached) curve data.

max_domain

float max_domain = 1.0

The maximum domain (x-coordinate) that points can have.

max_value

float max_value = 1.0

The maximum value (y-coordinate) that points can have. Tangents can cause higher values between points.

min_domain

float min_domain = 0.0

The minimum domain (x-coordinate) that points can have.

min_value

float min_value = 0.0

The minimum value (y-coordinate) that points can have. Tangents can cause lower values between points.

point_count

int point_count = 0

The number of points describing the curve.

point_{index}/left_mode

int point_{index}/left_mode = 0

The left TangentMode for the point at index.

Note: index is a value in the 0 .. point_count - 1 range.

point_{index}/left_tangent

float point_{index}/left_tangent = 0.0

The left tangent angle (in degrees) for the point at index.

Note: index is a value in the 0 .. point_count - 1 range.

point_{index}/position

Vector2 point_{index}/position = Vector2(0, 0)

The position of the point at index.

Note: index is a value in the 0 .. point_count - 1 range.

point_{index}/right_mode

int point_{index}/right_mode = 0

The right TangentMode for the point at index.

Note: index is a value in the 0 .. point_count - 1 range.

point_{index}/right_tangent

float point_{index}/right_tangent = 0.0

The right tangent angle (in degrees) for the point at index.

Note: index is a value in the 0 .. point_count - 1 range.

add_point

int add_point(position: Vector2, left_tangent: float = 0, right_tangent: float = 0, left_mode: TangentMode = 0, right_mode: TangentMode = 0)

Adds a point to the curve. For each side, if the *_mode is TANGENT_LINEAR, the *_tangent angle (in degrees) uses the slope of the curve halfway to the adjacent point. Allows custom assignments to the *_tangent angle if *_mode is set to TANGENT_FREE.

bake

void bake()

Recomputes the baked cache of points for the curve.

clean_dupes

void clean_dupes()

Removes duplicate points, i.e. points that are less than 0.00001 units (engine epsilon value) away from their neighbor on the curve.

clear_points

void clear_points()

Removes all points from the curve.

get_domain_range

float get_domain_range() const

Returns the difference between min_domain and max_domain.

get_point_left_mode

TangentMode get_point_left_mode(index: int) const

Returns the left TangentMode for the point at index.

get_point_left_tangent

float get_point_left_tangent(index: int) const

Returns the left tangent angle (in degrees) for the point at index.

get_point_position

Vector2 get_point_position(index: int) const

Returns the curve coordinates for the point at index.

get_point_right_mode

TangentMode get_point_right_mode(index: int) const

Returns the right TangentMode for the point at index.

get_point_right_tangent

float get_point_right_tangent(index: int) const

Returns the right tangent angle (in degrees) for the point at index.

get_value_range

float get_value_range() const

Returns the difference between min_value and max_value.

remove_point

void remove_point(index: int)

Removes the point at index from the curve.

sample

float sample(offset: float) const

Returns the Y value for the point that would exist at the X position offset along the curve.

sample_baked

float sample_baked(offset: float) const

Returns the Y value for the point that would exist at the X position offset along the curve using the baked cache. Bakes the curve’s points if not already baked.

set_point_left_mode

void set_point_left_mode(index: int, mode: TangentMode)

Sets the left TangentMode for the point at index to mode.

set_point_left_tangent

void set_point_left_tangent(index: int, tangent: float)

Sets the left tangent angle for the point at index to tangent.

set_point_offset

int set_point_offset(index: int, offset: float)

Assigns the horizontal position offset to the point at index.

set_point_right_mode

void set_point_right_mode(index: int, mode: TangentMode)

Sets the right TangentMode for the point at index to mode.

set_point_right_tangent

void set_point_right_tangent(index: int, tangent: float)

Sets the right tangent angle for the point at index to tangent.

set_point_value

void set_point_value(index: int, y: float)

Assigns the vertical position y to the point at index.