in the Dodge tutorial i get invalid operators "vector2" and "Nil"

spyrox16spyrox16 Posts: 2Member
edited October 2018 in Tutorials

extends Area2D

export (int) var SPEED
var velocity = Vector2()
var screensize

func _ready():
screensize = get_viewport_rect().size

func _process(delta):
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.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0: # normalizing = 1
21. velocity = velocity.normalized() * SPEED
velocity = velocity.normalized() * SPEED
position += velocity * delta
pass

Invalid operands 'Vector2' and 'Nil' in operator '*'.
Error in line 21.

Answers

  • spyrox16spyrox16 Posts: 2Member
    edited October 2018

    Problem solved. Didn't initialized the speed value.

Sign In or Register to comment.