PathFollow2D
Inherits: Spatial2D < CanvasItem < Actor < Object
Point sampler for a Path2D.
Description
Section titled “Description”This actor takes its parent Path2D, and returns the coordinates of a point within it, given a distance from the first vertex.
It is useful for making other actors follow a path, without coding the movement pattern. For that, the actors must be children of this actor. The descendant actors will then move accordingly when setting the progress in this actor.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| bool | cubic_interp | true |
| float | h_offset | 0.0 |
| bool | loop | true |
| float | progress | 0.0 |
| float | progress_ratio | 0.0 |
| bool | rotates | true |
| float | v_offset | 0.0 |
Property descriptions
Section titled “Property descriptions”cubic_interp
Section titled “cubic_interp”bool cubic_interp = true
Setter/getter: set_cubic_interpolation(), get_cubic_interpolation()
If true, the position between two cached points is interpolated cubically, and linearly otherwise.
The points along the Curve2D of the Path2D are precomputed before use, for faster calculations. The point at the requested offset is then calculated interpolating between two adjacent cached points. This may present a problem if the curve makes sharp turns, as the cached points may not follow the curve closely enough.
There are two answers to this problem: either increase the number of cached points and increase memory consumption, or make a cubic interpolation between two points at the cost of (slightly) slower calculations.
h_offset
Section titled “h_offset”float h_offset = 0.0
Setter/getter: set_h_offset(), get_h_offset()
The actor’s offset along the curve.
bool loop = true
Setter/getter: set_loop(), has_loop()
If true, any offset outside the path’s length will wrap around, instead of stopping at the ends. Use it for cyclic paths.
progress
Section titled “progress”float progress = 0.0
Setter/getter: set_progress(), get_progress()
The distance along the path, in pixels. Changing this value sets this actor’s position to a point within the path.
progress_ratio
Section titled “progress_ratio”float progress_ratio = 0.0
Setter/getter: set_progress_ratio(), get_progress_ratio()
The distance along the path as a number in the range 0.0 (for the first vertex) to 1.0 (for the last). This is just another way of expressing the progress within the path, as the offset supplied is multiplied internally by the path’s length.
It can be set or get only if the PathFollow2D is the child of a Path2D which is part of the scene tree, and that this Path2D has a Curve2D with a non-zero length. Otherwise, trying to set this field will print an error, and getting this field will return 0.0.
rotates
Section titled “rotates”bool rotates = true
Setter/getter: set_rotates(), is_rotating()
If true, this actor rotates to follow the path, with the +X direction facing forward on the path.
v_offset
Section titled “v_offset”float v_offset = 0.0
Setter/getter: set_v_offset(), get_v_offset()
The actor’s offset perpendicular to the curve.