Why will my movement code not work or kinda dose then it crashs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fusegene Studios
extends KinematicBody2D

var speed = 200
var velocity = Vector2()

func _ready():

func _physics_process(delta):
	velocity = Vector2()
	if Input.is_action_pressed("up"):
		velocity -= speed
	if Input.is_action_pressed("down"):
		velocity.y += speed
	if Input.is_action_pressed("left"):
		velocity.x += speed
	if Input.is_action_pressed("right"):
		velocity.x -= speed

Edited to fix code formatting. In future posts, please use the {} button to format code in your posts. Otherwise, it’s difficult to read.

jgodfrey | 2023-02-03 22:07

Are you really using Godot 3.2.1? If so, I wonder why you’re using such an old version?

jgodfrey | 2023-02-03 22:10

that version was realeased in 2022 google says how is it old

Fusegene Studios | 2023-02-03 22:17

Not sure what info you’re looking at. According to this article, it was released in March of 2020.

jgodfrey | 2023-02-03 22:25

The current release is 3.5.1. Download from here (if you want).

jgodfrey | 2023-02-03 22:26

i did not mean to say 2022 I meant to say 2020 mis said it sorry

Fusegene Studios | 2023-02-04 02:19

:bust_in_silhouette: Reply From: Anaxarchus
if Input.is_action_pressed("up"):
    velocity -= speed

needs to be:

if Input.is_action_pressed("up"):
    velocity.y -= speed

you can multiply and divide vectors by scalars, but you cannot add or subtract them.