my camera is moving, but what I am viewing isn't, how can I fix that?

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

I’m using some code to move a camera with an animated sprite as a child, but when I move it, what I am moving doesn’t move the camera, but it moves the sprite. I used print to see if the camera is moving too and it was. any Idea on why that’s happening, do I have to link the camera or something? I am knew to Godot so if you could help that would be appreciated.
This is in 2D by the way.

Please share your code and your scene tree. If we can’t see your project, it’s very difficult to help you.

Bernard Cloutier | 2020-10-07 15:41

extends Node2D;
func moveLeft():
if Input.is_key_pressed(KEY_LEFT):
$Camera2Disme.position = Vector2($Camera2Disme.position+ Vector2(-3,0))
func moveUp():
if Input.is_key_pressed(KEY_UP):
$Camera2Disme.position = Vector2($Camera2Disme.position+ Vector2(0,-3))
func moveDown():
if Input.is_key_pressed(KEY_DOWN):
$Camera2Disme.position = Vector2($Camera2Disme.position+ Vector2(0,3));
func _process(delta):

if Input.is_key_pressed(KEY_RIGHT):
	$Camera2Disme.position = Vector2($Camera2Disme.position+ Vector2(3,0))
print($Camera2Disme.position )

ILearnToCode | 2020-10-07 22:28

Could you also share what your scene tree looks like? And I mean take a screenshot and post it. Or write it in text like so:

  • Top Node

  • Child1

    • Subchild1

    • Subchild2

  • Child2

With the information you’ve given, I can’t know the relationship between the sprite node and the camera node. Is one the parent of the other? This makes it hard for me to help.

Also, when pasting code, highlight it and press the curly braces icon in the editor. It will format it like this:

func _my_func():
    if _my_func2():
    return true

Which you’ll agree is much easier to parse than this:

func _my_func():
if _my_func2():
return true

Is return true part of the if block? No way to know without proper formatting.

Anyway, in the code you posted you seem to be moving the camera. Is your scene only a camera and a sprite? If so, it will seem like the sprite is moving in the opposite direction.

Bernard Cloutier | 2020-10-08 00:41

  • node2D

    • textureRect1-10

    • camera2D

      • animatedSprite
        • area2D

ILearnToCode | 2020-10-08 13:56

:bust_in_silhouette: Reply From: PipeVerri

is your camera on current mode?

like I said I am new to godot so I dont know what that means.

ILearnToCode | 2020-10-08 13:57

thanks everyone, I searched how to put a camera in current mode and figured it out you guys are amazing, keep up the good work. :smiley:

ILearnToCode | 2020-10-08 14:13

sorry for not answering your comment before, i didnt saw any notification

PipeVerri | 2020-10-08 19:43