0 votes

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():
pass

func process(delta):
var velocity = Vector2() # The player's movement vector.
if Input.is
actionpressed("uiright"):
velocity.x += 1
if Input.isactionpressed("uileft"):
velocity.x -= 1
if Input.is
actionpressed("uidown"):
velocity.y += 1
if Input.isactionpressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized()*speed
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()

Godot version latest
in Engine by (12 points)

1 Answer

0 votes

Hello,
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.

by (728 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.