Attention | Topic was automatically imported from the old Question2Answer platform. | |
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?