Move_and_slide()

4.2.1

The ‘move_and_slide()’ function is giving me the error ‘Too many arguments for move_and_slide() call. Expected at most 0 but received 1.’ when the only argument I’m passing is velocity.

since Godot 4 you dont need to insert the parameter manually. Like:

velocity.x = 10

move_and_slide() # here you dont insert velocity. Godot is doing alone.

2 Likes

This is my code

extends CharacterBody2D
class_name Player 

@export var aceleracion = 300
var velocidad = Vector2()
var velo_rotacion = 1
var dire_rota = 0

func _physics_process(delta: float )-> void:
	obtener_input()
	rotation += dire_rota * velo_rotacion * delta
	velocidad = aceleracion
	move_and_slide()

	
	
	
func obtener_input():
	dire_rota = 0
	velocidad = Vector2()
	if Input.is_action_pressed("right"):
		dire_rota += 1
		
	if Input.is_action_pressed("left"):
		dire_rota -= 1
		
	if Input.is_action_pressed("down"):
		velocidad = Vector2(-aceleracion, 0).rotated(rotation)
	
	if Input.is_action_pressed("up"):
		velocidad = Vector2(aceleracion, 0).rotated(rotation)
		
	velocidad = velocidad.normalized() * aceleracion

function… :expressionless:

extends CharacterBody2D
class_name Player 

@export var aceleracion = 50
var velocidad = Vector2()
var velo_rotacion = 1
var dire_rota = 90

func _physics_process(delta: float )-> void:

	rotation += dire_rota * velo_rotacion * delta
	dire_rota = 0
	velocidad = Vector2()
	if Input.is_action_pressed("right"):
		dire_rota += 1
		print("hey")
	if Input.is_action_pressed("left"):
		dire_rota -= 1
		print("hay")
	
	if Input.is_action_pressed("up"):
		velocidad = Vector2(aceleracion, 0).rotated(rotation)
		print("no")
	if Input.is_action_pressed("down"):
		
		velocidad = Vector2(-aceleracion + 10, 0).rotated(rotation)
		print("si")
		
	translate(velocidad * delta)
	velocidad = velocidad.normalized() * aceleracion

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.