2 RigidBody2Ds + 1 PinJoint2D: strange behavior after set_pos / set_scale

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bruteforce
:warning: Old Version Published before Godot 3 was released.

Hi all,

I am in trouble again with my connected rigid bodies :)!

I want to flip a node horizontally, which contains 2 bodies and 1 pin joint.
The new positions and directions are correct now, but something is wrong with the joint.

The gravity scale properties are 0, and the bodies don’t move (this is OK), but after flipping, they start to rotate… I don’t know why :(.

If the joint’s nodeA and nodeB members are empty, everything looks good.

I have tried to clear nodeA and nodeB, and restore them at the end of my flip method, but it didn’t help…

It’s hard to explain, so I uploaded the sample project!
Link: google drive

The flip function is called when a mouse button is pressed.

There are no visible items in the project, so you have to turn on the “visible collision shapes” checkbox!
enter image description here

The clearJointNodes() and setJointNodes() function calls are commented now (root.gd: line 21 and 41).

Thanks for any help / suggestion!

I don’t know about your project, but setting the position and scaling are two things RigidBodies usually don’t like…

Zylann | 2017-03-09 13:49

I don’t scale the rigid body, only its child collision polygon. According to (the best answer) of my previous topic
But yes, I modify its position (with set_pos function). Is this a mistake?

There is a download link (google drive) to the simplified project, can you check it?

Thank you!

bruteforce | 2017-03-09 14:19

If I do these steps manually in the editor, evereything works fine … :confused:

Is there any way to dump an object (print all of the current member values)?
I would like to compare the 2 results (editor vs. script)!

bruteforce | 2017-03-09 17:42

Note that you can’t modify CollisionShape nodes from a script (in Godot 2 specifically), because these nodes are only meant to be used in the editor. To change shapes you have to use CollisionObject functions http://docs.godotengine.org/en/stable/classes/class_collisionobject.html#class-collisionobject

Zylann | 2017-03-09 21:36


I think there is some problem with collision of these rigidBodies.
Change the collision mask and layer for any of the rigidBodies.
and it will run fine.

May be this will help

GamerDev | 2018-07-05 07:20