My character does the animation but doesn't move

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

I’m learning to do progamation, I’m new in the Godot engine, my first code make the character play the animation, but he don’t move, can someone explain me why?

extends Area2D

export var speed = 400
var screen_size

func _ready():

func _process(delta):
var velocity = Vector2() # The player’s movement vector.
if Input.is_action_pressed(“ui_right”):
velocity.x += 1
if Input.is_action_pressed(“ui_left”):
velocity.x -= 1
if Input.is_action_pressed(“ui_down”):
velocity.y += 1
if Input.is_action_pressed(“ui_up”):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized()*speed

:bust_in_silhouette: Reply From: Lola

The reason your character is not moving is simply because nothing in your script is modifying its position (your calculate the velocity but you don’t apply it).
So, something you could do is:

func _process(delta):
    # here calculate the velocity
    # then apply the velocity (move the object)
    position = position + delta * velocity

If you are a very begginer I recommend you to follow this which covers the basics.