Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SnickeringSnickers |
I’m trying to algorithmically create a softbody circle using code.
I’ve managed to create the circle properly
when the bodies are static
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
when the center node is static and the outside ones are rigid they all slink down like they should
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():
points.resize(count)
col_points.resize(count)
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(col_points[n].get_node("clock").get_node_a())
print("linked to")
print(col_points[n].get_node("clock").get_node_b())
print("===========")
else:
#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(col_points[n].get_node("clock").get_node_a())
print("linked to")
print(col_points[n].get_node("clock").get_node_b())
print("===========")