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.

asked Jul 5 in Engine by pengyou (42 points)
edited Jul 5 by pengyou

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 How to use this Q&A? before posting your first questions.