Dodge the Creeps player not moving at all

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

I have followed the code provided in the tutorial but the player stays still and does not move.

My player script looks as follows:

extends Area2D


# Declare member variables here.
export var speed = 400
var screen_size


# Called when the node enters the scene tree for the first time.
func _ready():
	 screen_size = get_viewport_rect().size


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	
	var velocity = Vector2()
	
	if Input.action_press("ui_right"):
		velocity.x += 1
	if Input.action_press("ui_left"):
		velocity.x -= 1
	if Input.action_press("ui_down"):
		velocity.y += 1
	if Input.action_press("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, screen_size.x)
	position.y = clamp(position.y, 0, screen_size.y)

Could someone please provide me with feedback on how to solve this issue?

:bust_in_silhouette: Reply From: Zylann

Your input is wrong. Here is what the tutorial has:

if Input.is_action_pressed("ui_right"):
    velocity.x += 1
...

And here is what you wrote:

if Input.action_press("ui_right"):
    velocity.x += 1
...

It should be is_action_pressed, not action_press.

(action_press simulates the press of a key and returns nothing, it does not check if that key is pressed)

Thank you for your help. It works correctly now.
Seems silly now that I did not notice it.

msherif | 2020-09-15 12:59