Godot Version
4.7.2 Stable
Question
I’m wondering how to properly attach another physics body to a pin joint 2D during runtime. When I try to do it like how I have below, the node_b (the player in this case) doesn’t seem to be affected by any physics that the PinJoint should exert. There’s also weird behavior when I try to print out the node_b, as it prints out empty lines. I can’t see it in the output, but apparently there are messages that fill it up as indicated by the exclamation mark. Any help is greatly appreciated, thank you.
This is what the output looks like.
@onready var player : Player
func _ready() -> void:
player = get_parent()
func _process(_delta: float) -> void:
if is_colliding():
var collider = get_collider()
if collider is hookable_object:
var pin_joint : PinJoint2D = collider.find_child("PinJoint")
if pin_joint:
pin_joint.set("nodes/node_b", player.get_path()) #sets node b
print(pin_joint.node_b)
