Dodge the Creeps character won't move

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

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)

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.

kidscancode | 2019-10-26 22:05

:bust_in_silhouette: Reply From: kidscancode

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.

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

AstralRollerblades | 2019-10-26 23:29

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

kidscancode | 2019-10-26 23:33

Imgur: The magic of the Internet here’s my entire script,the problem stays the same ;_; ,thank you very much friend.

AstralRollerblades | 2019-10-27 00:17

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

wetfish | 2020-01-23 08:24