Code doesn't work in new project, but works in old one

Godot Version 4

Btw I’m new to coding, so this all could very much be me typing in the wrong code

I started a new project and copied my code from my first one, though when I put it in my new one it doesn’t work. I added more lines of code (to play idle animations), but thats it. I have the same input settings and everything. I don’t know if I typed the code in wrong or if its the idles that killed it, any help? It says the issue is the distance.length part. but it worked in my first project, so I don’t know what to do.

extends CharacterBody2D

@export var speed = 500
@export var friction = 0.1
@export var acceleration = 0.5

func get_input():
	
	var input = Vector2()
	
	if Input.is_action_pressed("walk_up"):
		input.y -= 1
		$character_animations.play("5_walk back")
		print("walking up")
	elif Input.is_action_pressed("walk_down"):
		input.y += 1
		$character_animations.play("5_walk front")
		print("walking down")
	elif Input.is_action_pressed("walk_left"):
		input.x -= 1
		$character_animations.play("5_walk left")
	elif Input.is_action_pressed("walk_right"):
		input.x += 1
		$character_animations.play("5_walk right")
	if Input.is_action_just_released("walk_up"):
		$character_animations.play("1_Idle back")
	if Input.is_action_just_released("walk_down"):
		$character_animations.play("1_idle front")
	if Input.is_action_just_released("walk_left"):
		$character_animations.play("1_idle left")
	if Input.is_action_just_released("walk_right"):
		$character_animations.play("1_idle right")


func _physics_process(delta: float) -> void:
	var direction = get_input()
	if direction.length() > 0:
		velocity = velocity.lerp(direction.normalized() * speed, acceleration)
	else:
		velocity = velocity.lerp(Vector2.ZERO, friction)
	move_and_slide()

Your get_input() does not return a value. Adding return type will help this error message

func get_input() -> Vector2:

then make sure to return your input vector

return input
1 Like

I’m actually crashing out, I forgot to put return input TToTT

1 Like