0 votes

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?

in Engine by (679 points)

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.

1 Answer

0 votes
by (679 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.