Hi. I want to create an pin joint from code. I write some code and attach it to the "Player" node. My player moved, but joint not created. Thanks.
Creating joints from GDS
The reason the debugger is showing an error is because on line 21 you are using get_node, but without passing a node path to it, just an empty string. you probably need to replace line 21 with get_parent().add_child(myjoint)
and that should fix the script so it adds the node to the scene.
Also, looking at the script, this will make a new join every time the down action is pressed without removing the old joint. If you want to remove the old joint, then you'll need to replace lines 27+ with the following:
if Input.is_action_just_pressed("down"):
if (myjoint != null):
myjoint.queue_free()
myjoint = null
Hopefully this helps! (Side note: Welcome to the forums!)
Sorry, not help The problem yet here.
I wonder if the problem is related to this topic where another user was having issues creating joints from code.
Looking at this tutorial, it might be the problem is in how the nodepaths you are passing are formatted. Maybe try getting the nodes for each of the points using get_node
and then get_path()
and see if that helps?