Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MrGwasty |
this is how my code looks i tried everything re typing it taking other ppl codes looking at other q&a watching yt and trying to make a little change from my some what type of experience with gd script and nothing is working ONLY the vertical movment is working and only going up left so i dont really know what to do
extends Area2D
export var speed = 400
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_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.x = clamp(position.y, 0, screen_size.y)