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)
asked Oct 26, 2019 in Engine by AstralRollerblades (15 points)
edited Oct 26, 2019 by kidscancode

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

+1 vote
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.

answered Oct 26, 2019 by kidscancode (13,244 points)
selected Oct 26, 2019 by AstralRollerblades

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.