Creating joints from GDS

sergkisel3vsergkisel3v Posts: 4Member

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.


Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    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!)

  • sergkisel3vsergkisel3v Posts: 4Member

    Sorry, not help
    The problem yet here.

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    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?

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file