There are two problems and one improvement in your code.
Problems)
- The NodePath you specify using export(NodePath) is relative to the scene, but the NodePath you give to the Joint must be an absolute path.
- The joint you create must be added to the node tree before it will work.
Improvement)
- Rather than using set, use set_node_a, set_node_b which are more appropriate.
Specifically, we will do this.
extends Spatial
export(NodePath) var body1
export(NodePath) var body2
func add_bound(b1: NodePath, b2: NodePath):
var bound = Generic6DOFJoint.new()
bound.set_node_a(b1)
bound.set_node_b(b2)
add_child(bound)
func _ready():
add_bound(
get_node(body1).get_path(),
get_node(body2).get_path()
)