0 votes

I'm trying to algorithmically create a softbody circle using code.
I've managed to create the circle properly

when the bodies are static
enter image description here

They all appear to be linked when I check with print statements. They link to the center point correctly I believe, but when the bodies are set off of static they freak out and fling everything around.

when the bodies are set to rigid
enter image description here
when the center node is static and the outside ones are rigid they all slink down like they should
enter image description here

I've been scratching my head for hours this to me seems like it should work in theory

extends RigidBody2D

var count = 20
var radius = Vector2(40, 0)
var center = Vector2(0,0)
var col_points = []
onready var col = load("res://scenes/seg.tscn")

var step = 2 * PI / count

var points = [Vector2()]
# Declare member variables here. Examples:
# var a = 2
# var b = "text"

# Called when the node enters the scene tree for the first time.
func _ready():

    for n in range(count):
        var spawn_pos = center + radius.rotated(step * n) #spot to spawn the segment
        var seg_spawn = col.instance() #creates a instance of segment of the soft body child nodes are spring mid, spring clock, spring counter

        add_child(seg_spawn) #spawn's segment of the soft body
        seg_spawn.set_position(spawn_pos) #sets the postion of the soft body segment

        seg_spawn.get_node("mid").set_node_a(seg_spawn.get_path()) #current generated segment
        seg_spawn.get_node("mid").set_node_b(self.get_path()) #center segment
        col_points[n] = seg_spawn
        points[n] = spawn_pos

    for n in range(count):

        if(n < count-1):
            #links current segment to next segment 
            col_points[n].get_node("clock").set_node_a(col_points[n].get_path()) #links current segment
            col_points[n].get_node("clock").set_node_b(col_points[n+1].get_path()) #links next segment

            print("linked to")
            #links last segment to first
            col_points[count-1].get_node("clock").set_node_a(col_points[count-1].get_path()) #links last segment
            col_points[count-1].get_node("clock").set_node_b(col_points[0].get_path()) #links first segement

            print("linked to")

enter image description here

in Engine by (12 points)

Please log in or register to answer this question.

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.