Godot Version
4.2
Hello, I am new in godot and I am trying to learn to code in GDScript… I try to make a 2D character in a topdown view with movements but there is something that I do not understand… in Godot when Y < 0 should me up, right?
but why is working backwards?
This is what I am doing
and This is my code and everything works well:
extends Area2D
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
const PIXELS : int = 32
var tween : Tween
var moving : bool = false
var current_idle = “idle_down”
func _ready() → void:
pass
func _process(delta: float) → void:
var direction = Input.get_vector(“move_left”, “move_right”, “move_down”, “move_up”)
if direction && !moving:
moving = true
move_me(direction)
if !direction && !moving:
animation.play(current_idle)
func move_me(direction):
var next_position : Vector2
#moveup
if direction.y > 0:
next_position = position + Vector2(0, -PIXELS)
animation.play("walk_up")
current_idle = "idle_up"
move_by_tween(next_position)
#movedown
elif direction.y < 0:
next_position = position + Vector2(0, PIXELS)
animation.play("walk_down")
current_idle = "idle_down"
move_by_tween(next_position)
#moveleft
elif direction.x < 0:
next_position = position + Vector2(-PIXELS, 0)
animation.play("walk_left")
current_idle = "idle_left"
move_by_tween(next_position)
#moveright
elif direction.x > 0:
next_position = position + Vector2(PIXELS, 0)
animation.play("walk_right")
current_idle = "idle_right"
move_by_tween(next_position)
func move_by_tween(next_position : Vector2):
tween = create_tween()
tween.tween_property(self, “position”, next_position, 0.2)
tween.tween_callback(end_of_tween)
func end_of_tween():
moving = false
animation.play(current_idle)
So here I notice that when y > 0 and if I declare Vector2(0, PIXELS) this movement should be DOWN but Works backwards and vice versa. am I omiting something or understanding something wrong?
Excuse my english is really bad sorry.