Can DampedSpringJoint2D's length and rest length changed on run time?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By genete
:warning: Old Version Published before Godot 3 was released.

I would like to change the resting length (and maybe also the current length) of a DampedSpringJoint2D using GDScript.

This is what I tried but doesn’t work:

extends DampedSpringJoint2D

var length=100
var new_length=100

var node_a_path
var node_b_path

func _ready():
	set_process_input(true)
	set_fixed_process(true)
	node_a_path=get_node_a()
	node_b_path=get_node_b()
	pass

func _fixed_process(delta):
	if length==new_length:
		return
	length=new_length
	set_node_a("")
	set_node_b("")

	set_rest_length(length)
	set_length(length)

	set_node_a(node_a_path)
	set_node_b(node_b_path)

	pass

func _input(event):
	if event.is_action_pressed("ui_up") and not event.is_echo():
		new_length+=10
	if event.is_action_pressed("ui_down") and not event.is_echo():
		new_length-=10
	pass

Is that possible to do? And how? Once you run the project, those parameters can’t be changed?

The previous script changes the length and the rest length of the spring but the attached bodies doesn’t follow the new situation. Looks like is they are still attached to the initial joint definition.

genete | 2016-08-17 06:46

:bust_in_silhouette: Reply From: genete

Seems to be a bug there: