Pin object to another

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By indy2005


I am making a 2D game I originally created in Construct. One thing Construct has which is great, is the “Pin” behaviour. You can just pin one object to another, and it rotates and moves with it. I am trying to achieve the same in Godot. I am reparenting a node (a dagger sprite) to another node (a spinning target), but while it does reparent - the position goes out of the window. How do I ensure the dagger remains pinned at the right position as if the dagger stuck into the spinning target? I am assuming I have to convert the daggers world co-ordinates into local co-ordinates within the new parent node? I see there is a PinJoint2D but I am not using physics at all. I expect its made even more difficult by the fact the new parent is constantly rotating.



:bust_in_silhouette: Reply From: klaas

you can easyly convert locals to globals and vize versa with to_global() and to_local()


this would transform the daggers world position to the new_parents local position

Thanks, now the rotation is off…

indy2005 | 2020-09-14 22:01