0 votes

i follow all the tutorial steps but the character can't move..here's my script

extends Area2D

export (int) var SPEED
var screensize

func _ready():
    screensize = get_viewport_rect().size

func _process(delta):
    var velocity = Vector2() 
    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.x +=1
    if Input.is_action_pressed("ui_up"):
        velocity.x -=1
    if velocity.length() > 0:
        velocity = velocity.normalized() * SPEED
        $AnimatedSprite.play()
    else:
        $AnimatedSprite.stop()

        position += velocity * delta
        position.x = clamp(position.x, 0, screensize.x)
        position.y = clamp(position.y, 0, screensize.y)
in Engine by (15 points)
edited by

Note - your code is unreadable when you paste it like this. Please use the code formatting button, which you can see on top of the editor - it looks like {}. I've gone ahead and edited your post this time.

1 Answer

+2 votes
Best answer

Your problem is that the last three lines, which perform the movement, are indented under the else:, which means they would only be executed when the velocity's length is 0. Unindent them one level.

by (20,361 points)
selected by

Thanks for the help man,i unindented all three of them but now only the eyes move ;__; the character stays in the same position,but atleast its progress xD

Well, another problem I noticed is that you used x for your up and down movement, which should be y.

https://imgur.com/a/c9TNerS here's my entire script,the problem stays the same ;_; ,thank you very much friend.

Did you ever figure this out? I have the exact same problem.

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.