I have a problem with my script. can someone hely. its with the veliocity

line 46 and line 20 says error: excepted 0 but recieved 1

extends CharacterBody2D

const max_speed = 400
const accel = 1500
const friction = 600

var input = Vector2.ZERO
var current_dir = “none”

func _ready():
$AnimatedSprite2D.play(“front_idle”)

func _physics_process(delta):
player_movement(delta)

func get_input():
input.x = int(Input.is_action_pressed(“ui_right”)) - int(Input.is_action_pressed(“ui_left”))
input.y = int(Input.is_action_pressed(“ui_down”)) - int(Input.is_action_pressed(“ui_up”))
return input.normalized()

func player_movement(delta):
input = get_input()

# Beállítjuk az aktuális irányt az animációhoz
if input.x > 0:
	current_dir = "right"
elif input.x < 0:
	current_dir = "left"
elif input.y > 0:
	current_dir = "down"
elif input.y < 0:
	current_dir = "up"

# Mozgás logika (gyorsulás és fékezés)
if input == Vector2.ZERO:
	if velocity.length() > (friction * delta):
		velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
	else:
		velocity = Vector2.ZERO
	play_anim(0)
else:
	velocity = velocity.move_toward(input * max_speed, accel * delta)
	play_anim(1)

# Mozgás végrehajtása
move_and_slide(velocity)  # Itt már nem rendelünk vissza értéket a velocity-hoz

func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D

if dir == "right":
	anim.flip_h = false
	if movement == 1:
		anim.play("side_walk")
	elif movement == 0:
		anim.play("side_idle")
elif dir == "left":
	anim.flip_h = true
	if movement == 1:
		anim.play("side_walk")
	elif movement == 0:
		anim.play("side_idle")

if dir == "down":
	anim.flip_h = false
	if movement == 1:
		anim.play("front_walk")
	elif movement == 0:
		anim.play("front_idle")
elif dir == "up":
	anim.flip_h = false
	if movement == 1:
		anim.play("back_walk")
	elif movement == 0:
		anim.play("back_idle")

line 46 and line 20 says error: excepted 0 but recieved 1

It’s a little difficult to track down because your code has been formatted strangely on here!

But “line 46 and line 20 says error: excepted 0 but recieved 1” is implying that on those lines you have something like:
func player_movement(delta):
When it was expecting:
func player_movement():

The “delta” is the 1 it wasn’t expecting in those cases so it’ll be something like that :slightly_smiling_face:

move_and_slide takes zero arguments, but you are giving it one. remove velocity here.

1 Like

Spot on @gertkeno! (maybe i shouldn’t try and help here on my phone haha!)

I see that a lot in older tutorials.