Godot Version
v4.5.stable.fedora [876b29033]
Question
I have a fallen log object that i want the player to be able to pull, and I believe the best way to do that is with DampedSpringJoint2D. I made the player a RigidBody2D, because i found it easier to make the player be able to push and pull other rigid bodies that way. Pushing works perfectly, while pulling seems to be really hard to do.
What i have tried is creating an area around the player. While the pull button is pressed, it will create a spring joint that connects to all rigid bodies in the area. This is the pull function:
func pull():
if Input.is_action_pressed("pull"):
for n in pull_area.get_overlapping_bodies().size():
var body = pull_area.get_overlapping_bodies().get(n)
var rope = DampedSpringJoint2D.new()
add_child(rope)
rope.node_a = self
rope.node_b = body
pull() is called in _physics_process. It seems though that it’s not possible to connect the spring joint to self, as the game crashes with this error message:
E 0:00:02:206 pull: Invalid assignment of property or key 'node_a' with value of type 'RigidBody2D (player_rigid_body.gd)' on a base object of type 'DampedSpringJoint2D'.
<GDScript Source>player_rigid_body.gd:59 @ pull()
<Stack Trace> player_rigid_body.gd:59 @ pull()
player_rigid_body.gd:22 @ _physics_process()