Rotate the entire stage by 180° around pivot

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

Hello there!

I want to flip / rotate the entire stage with the player being the pivot.
I tried with rotating the Camera2D by 180°, which worked almost fine. The only problem I have is the ParallaxBackgrounds going crazy when rotating the camera. (I think they are rotating around global (0|0))

Is there a possibility to rotate the ParallaxBackgrounds and their Layers correctly? Or is there an even better approach to achieve this world-flip?

Best regards!

:bust_in_silhouette: Reply From: Mohammad Hadi Aliakb

I think you can rotate the currentscene for getting it you can get it using get_tree().get_current_scene()

But doesn’t it rotate around (0|0)?
Thank you! I’ll try when I’m back home…

timoschwarzer | 2016-03-09 08:18

Dont forget to use backquotes (`) when writing code snippets, so that the underscores are not interpreted as italic tag, see How to write underscore "_" in comments? - Archive - Godot Forum

I fixed it here though :slight_smile:

Akien | 2016-03-09 12:46

:bust_in_silhouette: Reply From: thomas_laverne

You may prevent the rotation of the parallax background by ticking the option “unfollow camera” (I don’t remember the exact name). I hope it helps :wink:

There is only “Ignore Camera Zoom” for the ParallaxBackground

timoschwarzer | 2016-03-09 15:33

Yep, that’s it! But I guess you might want your parallax to rotate as well… Not a good solution I suppose.

thomas_laverne | 2016-03-09 15:36

Isn’t it possible to flip the entire viewport by 180°?

timoschwarzer | 2016-03-09 16:05

:bust_in_silhouette: Reply From: gau_veldt

You can parent whatever you want to rotate to a Node2D (I’ll call it “NodeParent”) and rotate that Node2D to result in rotation of everything under it (children) rotated by calling NodeParent.set("transform/rot",angle). (angle is a var holding the rotate angle). If it is not rotating around the desired point (center in your case) you may change it with NodeParent.set("transform/pos",SomeVector2) where SomeVector2 is just a Vector2 var whose x and y members hold the translational offset. PS: Make angle and SomeVector2 into export members to have the pivot and rotation adjustable in the editor and accessible to animations.

Unfortunately, this doesn’t work with ParallaxBackgrounds since they are CanvasLayers and rotate around (0|0)

timoschwarzer | 2016-03-10 15:24

A really doozy way is to make that parallax node a child to a different Viewport rendering to a texture via .set_as_render_target(true) then have a sprite display that texture in the main visible Viewport (the one you are rotating). it will rotate with the camera just like any other sprite would.

gau_veldt | 2016-07-15 04:25

:bust_in_silhouette: Reply From: twinpigs

Try to add CanvasLayer with negative Layer value:

enter image description here

Desired background image should be attached to it. In my case it’s “Sprite 2”.
Than in _process() of your Player’s script (for instance) you write code like following:

get_parent().get_node("CanvasLayer/Sprite 2").set_rot(-get_rot())

So you just attaching inverted Player’s rotation to your background.

Or you can get current rotation of camera instead of player’s rotation depending on your game design.

twinpigs | 2017-01-13 09:54