How do i create a pinJoint2d via gdScript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PipeVerri

I tried with this code in my Node2d:

func _ready():
  var node = PinJoint2D.new()
  node.set_node_a("part1")
  node.set_node_b("part2")
  add_child(node)

When i run it, it behaves like there isnt a joint there

:bust_in_silhouette: Reply From: njamster

The NodePaths you’re using are wrong - unless part1 and part2 are children of the PinJoint2D you’re adding via code. If your tree looks like this:

- Root
  - part1
  - part2
  - PinJoint2D (added at runtime)

then the paths have to be “…/part1” and “…/part2” respectively. They have to be relative to the PinJoint-path, not the path of the node who adds the PinJoint.

Thank you, now it works

PipeVerri | 2020-09-13 21:13