Manipulate the 2D "camera"

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

Hi everyone! i’m brand new to Godot, coming from a very intensive and exclusive Blender 3D background. Godot first attracted me because of it’s native 2D game engine, but i’ve run into a problem!

Since the “camera” or the view area for the 2D game isn’t an object, i have no idea how to manipulate it in the game! Specifically, i’m looking to do rotation, but just understanding how to manipulate the camera in the 2D game engine is my goal.

:bust_in_silhouette: Reply From: Zylann

You can create a Camera node and set it as current in the inspector. Then you can move and rotate it just like any other Node2D.

:bust_in_silhouette: Reply From: cardoso

I will describe a typical situation, with camera “attached” to the player.
Assuming you have a simple scene with a child node that is your character.
In the editor:
a) create a Camera2D node as a child of the character.
b) on the camera properties select “Current”. That is it!
c) customize. For example, in the “Limit” properties a left with value 0 means that the camera will stop moving left when the character has position 0 or below relative to the root node of the scene (I think).
In “Drag Margin” properties a right value of 0.2, for example, causes the camera to only start moving to the right if the center of the camera is 20% to the right of the player center.

To rotate the camera I suppose you would select Rotating in the editor + in the code use rotate() or set_rot(). I have never tried them.
Assuming you have in the root node a character node named “character” with a child camera named “Camera2D”:

get_node("character/Camera2D").set_rot(2)

You can also set the rotation in the editor, but I am guessing you want dynamically in the code.

Hope I helped.

woo hoo! thank you both very much!

Vincent Scalia | 2016-06-06 03:25