Dodge The Creeps player not moving

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

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

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.

:bust_in_silhouette: Reply From: Magso

Make SPEED a float. As an int, the line velocity = velocity.normalized() * SPEED might be returning 0.

also position += velocity * delta will cause it to constantly accelerate because += and -= are being used on the Vector2 already, use position = velocity * delta

:bust_in_silhouette: Reply From: brainbug

Did you set the Speed value in the inspector ?
The default value is 0 !
Try `export(int) var SPEED = 400

position += velocity * delta  

is correct

dont use

position = velocity * delta

that was wrong!!