0 votes

I have a shooting darts (KinematicBody2D) that will stick on a moving wall (staticbody2D).
I wants to let the dart stick on the wall, which is moving over time by changing position.x.
However, the dart does not follow fully the moving path of the wall.

I end up adding pinJoint2D, but setting the node via gdscript only give me an error

Invalid set index 'node_b' (on base: 'PinJoint2D') with value of type 'StaticBody2D (StaticBody2DWall.gd)'.

My code in dart node for setting up pinjoint2d goes as below:

var slide_count = get_slide_count()
if slide_count:
    var collision = get_slide_collision(slide_count - 1)
    var collider = collision.collider
    lif collider.is_in_group("wall"):
        $PinJoint2D.node_b = collider

Anyone please help. Please let me know if there's a better practice.

in Engine by (72 points)
edited by

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.