Move and slide ruins my code

why doesn’t it work?
what does
< Too many arguments for “move_and_slide()” call mean. Expected at most 0 but received 2. >

It means exactly what the error says :slight_smile:
move_and_slide() method doesn’t accept any arguments, you just call it raw as move_and_slide().

And you need to set your velocity directly into the velocity parameter before you call this method, so just use velocity instead of vel in your code and remove all arguments from the move_and_slide() method.

1 Like

move_and_slide used to take parameters in Godot 3.x. If you are copying code from tutorials/ChatGTP you will need to make sure it’s for your version of Godot. Which I assume from your error is 4.x

1 Like
 
var accel = 8
var speed = 12 
var jump = 9 
var sens = 0.1
var _delta 
 
var direction = Vector2()
var vel = Vector3()
 
var gravity = -22
var max_grav = -30
 
onready var head = $head
 
 
func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 
func _physics_process(delta):
    _delta = delta #определяем дельта для функций
    dir()
 
func _input(event):
    if event is  InputEventMouseMotion:
        var movement = event.relative
        head.rotation.x += -deg2rad(movement.y * sens)
        head.rotation.x = clamp(head.rotation.x , deg2rad(-90), deg2rad(90))
        rotation.y += -deg2rad(movement.x * sens)
        
func dir():
    direction = Vector2(0,0)
    if Input.is_action_pressed("+w"):
        direction.y -= 1
    elif Input.is_action_pressed("+s"):
        direction.y += 1
    if Input.is_action_pressed("+a"):
        direction.x -= 1
    elif Input.is_action_pressed("+d"):
        direction.x += 1
    direction = direction.normalized().rotated(-rotation.y)
    vel.x = lerp(vel.x, direction.x * speed, accel * _delta)
    vel.z = lerp(vel.z, direction.y * speed, accel * _delta)
    
    vel.y += gravity * _delta
    
    if vel.y < max_grav:
        vel.y = max_grav
    if Input.is_action_just_pressed("+space") and is_on_floor():
        vel.y = jump #прыжок
    
    move_and_slide(vel,Vector3.UP) #двигаемся
    
    if is_on_floor() and vel.y < 0: #если мы стоим на полу значит мы не падаем :D
        vel.y = 0

if it can help, here is the code that I adjusted to suit my needs