How to make something able to be stuck together with another object?

Godot Version

4.6

Question

Hiiiiiii! This is a very weird quiestion lol.

You know how you can glue two things together with a gluestick? Well, i got my game set up where you can drag all he objects i want the player to be able to drag around the 2d area. But i want to make it so that if those bodies are colliding, the player can take the (lets say) gluestick and stick them together, but not have the two things stick together without that gluestick. But i also dont want the player to be able to just put random things together. Any ideas?

Draggable script:

extends StaticBody2D

var dragging = false
var of = Vector2(0,0)


func _process(delta):
	if dragging:
		position = get_global_mouse_position() - of

func _on_button_button_down():
	dragging = true 
	of = get_global_mouse_position() - global_position


func _on_button_button_up():
	dragging = false

(also, im sure i could figure this out on my own real quick, but does anyone know off hand how to make the function where if you spin your mouse wheel, an object will rotate? thanks :smiley: if no one knows it off hand thats okay though ill find it ^^)

the glustick can reparent one of the objects to another object.

also you can use joints to do that

look_at(get_global_mouse_position)

how would i make it, though, so when all the objects are parented correctly, it would run the rest of the scene? WOuld it be a constant, like,

on reparent:

if (object) is parented to (this object):

and then so on, or is there a simpler way?

# glustick codes
object.make_rep (another_object)
# object codes
func make_rep(objc):
    reparent(objc)

you cant use object.reparent(another_object) ; becuse it wont work generaly ; the written codes before ; can solve your matter