Repository navigation
DampedSpring2D
Inherits: Object
A damped spring that smooths a Vector2 value toward a target.
A spring instance. You should create and update one spring instance for each value you wish to smooth.
See also DampedSpring and DampedSpring3D for the float/Vector3 equivalents.
var spring := DampedSpring2D.new()
@export var spring_params: DampedSpringParameters
func _process(delta: float) -> void:
follower.position = spring.update(delta, follower.position, target.position, spring_params)| Type | Name | Default | Description |
|---|---|---|---|
Vector2 |
velocity | Vector2(0, 0) |
The spring's current rate of change, advanced in place by update. Usually left for update to manage; can be read or set directly to inspect the spring's momentum, reset it, or give it an initial velocity. |
Updates the spring inertia state, and returns a new value.
Call this once per frame (or physics tick), passing in the value returned by the previous call as value.
If parameters is null, velocity is left unchanged and value is returned as-is.
Vector2 update_blend(float delta, Vector2 value, Vector2 target_value, DampedSpringParameters parameters_a, DampedSpringParameters parameters_b, float weight)
Like update, but blends smoothly between two DampedSpringParameters tunings instead of using just one: the spring/damping constants used for this step are linearly interpolated between parameters_a and parameters_b by weight (0.0 = fully parameters_a, 1.0 = fully parameters_b). Useful for crossfading between two "feels" (e.g. a relaxed and a snappy tuning) over time, rather than jumping between them.
If either parameters_a or parameters_b is null, velocity is left unchanged and value is returned as-is.
Vector2 update_constants(float delta, Vector2 value, Vector2 target_value, float spring_constant, float damping_constant)
Like update, but takes the spring's spring_constant/damping_constant coefficients directly instead of a DampedSpringParameters resource -- e.g. spring_constant/damping_constant, or values computed/blended by the caller.
This method is added for advanced manual spring blending use cases, or if you wish to specify damped spring parameters in a different way.
Documentation for the DampedSprings GDExtension addon.