Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Fullhammer |
Trying to make “Catch the creep” from tutorial, but after adding
‘if velocity.length() > 0:
velocity = velocity.normalized() * speed’
My blob don’t move and just play animation
Here is full code what i did
extends Area2D
export var speed = 400
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(_delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 10
if Input.is_action_pressed("ui_left"):
velocity.x -= 10
if Input.is_action_pressed("ui_down"):
velocity.y += 10
if Input.is_action_pressed("ui_up"):
velocity.y -= 10
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)