+2 votes

how to make a PinJoint2D between two existing RigidBody2D from script?
Thanks in advance.

in Engine by (1,469 points)
edited by

This is a Q&A site, not a forum. You should not add "Resolved" to the title, but instead, select/accept an answer.

I'm sorry , I correct immediately...

2 Answers

0 votes
Best answer

Resolved: before create joint must be to set a name for object instance

    for i in range(NUM_PARTS): 

      var p = part.instance()


      var pospartX = get_pos().x - 24*(i+1)
      var pospartY = get_pos().y

      p.set_pos(Vector2(pospartX, pospartY))


    for i in range(2,NUM_PARTS):

      var j = PinJoint2D.new()
by (1,469 points)
selected by

Hello, I am trying to do a rope and I have a similar problem.
In which function did you run that code? the _ready? or _init?

In _ready function

0 votes

I may have found, the code should be this :

    var joint = PinJoint2D.new()
    joint.set_node_b()    #this is a problem with instance object

The problem comes with the object instances . The argument of " set_node_a " and " set_node_b " functions takes the path to the object.
But how to do when the object is created at runtime (instance()) ?

by (1,469 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.