This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

in Engine by (17 points)

2 Answers

+1 vote

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

by (3,259 points)
0 votes

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!!

by (300 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.