Attention | Topic was automatically imported from the old Question2Answer platform. | |
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):
moveDown();
moveLeft();
moveUp();
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():
print("...")
return true
Which you’ll agree is much easier to parse than this:
func _my_func():
if _my_func2():
print(“…”)
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
-colisionShape2D
- area2D
- animatedSprite
-
ILearnToCode | 2020-10-08 13:56