Sprites not moving properly?

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

I am trying to make the catch the creep program but the sprite won’t move have gotten up to the part where its meant to be in the center of the screen and moving but the sprite is off to the left for some reason and won’t move.

Maybe you have skipped some part, but give more details because with that little information nobody will be able to help you.

eons | 2018-06-25 17:21

Oh sorry i didn’t include enough details its the same code from the catch the creep starter program. The code so far is:

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)

(sorry if its too long i’m not sure if i can hide the code.)

If you want anything else from it just ask.

keatit71 | 2018-06-26 10:21

Are you sure you gave SPEED a value different than zero?
Code looks fine to me.

DodoIta | 2018-06-26 11:12