![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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