Rotate parent and child nodes

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

Hey all,

I trying to create a mechanic in which a group of sprites controlled by a parent (Area2D) node will rotate. Not in place, but like the face of a clock. Also in a counter clock wise direction.

Additionally, there is one sprite child within the parent node that will be the rotational axis, so technically it would rotate in place.

Link to photos of what I’m going for. The glowing sprite would be the rotational axis.

What should I use to achieve this?
Additionally, how could i add a tween to this to make it smooth?

Thanks,

:bust_in_silhouette: Reply From: Joel_127

Simply use a node for your rotation pivot (you can name it “Pivot”), and all the children of the pivot rotate with the pivot. Nothing to code, this is automatic :slight_smile:

Hmm,

Perhaps i should have been more specific.

When the player presses shift i want all the player sprites to rotate counterclockwise on the map around the sprite that is in control. Hence it being a pivot point, but im unsure of what to do at run time to achieve this. scene tree pic here

An area2D node acts as the group so children sprites can move between them and ‘combine’. So how would I rotate the area2d node in place essentually?

sugarbrace901 | 2019-04-05 07:27

to rotate a node at runtime you simply use the “rotate” function Node2D — Godot Engine (3.1) documentation in English

Now if you want to change the pivot, you need to move it to where you want it to be, and parent the nodes you want to rotate to the pivot using the functions “remove_child”, “add_child”, or delete them and re-create them using “queue_free” and “instance()”

So, first remove the children from the current pivot node (you need to convert the location from local to global), then move the pivot node to where the rotation center needs to be, and add the children to the pivot node (converting the positions from global to local)

Not sure it is clear enough, but I hope it helps :slight_smile:

Joel_127 | 2019-04-05 09:31

Thanks!

I figured it out actually. I forgot to move the parent from the top left at where it spawns in the scene to the center of the child node in control. So it was rotating, but the parent was not in the correct location. Duh!

sugarbrace901 | 2019-04-05 17:05