0 votes

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

    position += velocity * _delta
    position.x = clamp(position.x, 0, screen_size.x)
    position.y = clamp(position.y, 0, screen_size.y)
Godot version 3.4.4.stable
in Engine by (12 points)

1 Answer

+1 vote

You have put main branch of code under ELSE statement. Position += velocity * delta abd clamping position must be indented left.

by (2,394 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.