I am having a problem with the dodge the creeps tutorial. After staring for about an hour now at my code which is identical to the code in the video tutorial ( https://youtu.be/XA1TPg6yiiA ) I can't seem to figure out why my player won't move. When I press my arrow keys the animation changes back and forth like it should but the character does move. Here is the code:
extends Area2D
export (int) var SPEED
var velocity = Vector2()
var screensize
func _ready():
screensize = get_viewport_rect().size
func _process(delta):
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.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 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)
Also the code indentation is correct just that it doesn't let you have different indents when asking questions here.