Move_and_slide() isn't working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Doughnut

when ever i put anything in the brackets it says “too many arguments for “move_and_slide()” call. expected at most 0 but received 1.”

The code is for a monster that walks left & right until it hits a wall or edge then it turns around. The code i was using is:

extends CharacterBody2D

var speed = 100
var direction = Vector2.LEFT

func _physics_process(float):
var velocity = direction * speed
var collision = move_and_slide(velocity)
if is_on_wall():
direction = -direction
$Sprite.flip_h = not $Sprite.flip_h

if you can’t find a fix, can you give me a work around?

Doughnut | 2023-03-16 14:06

:bust_in_silhouette: Reply From: SteveSmith

It looks like you’re using Godot4. Move_and_slide doesn’t take any params in Godot4 (it did in Godot3). See CharacterBody2D — Godot Engine (latest) documentation in English

Ok thanks for the info

Doughnut | 2023-03-17 12:59

hello, then what should I use instead of move_and_slide?

move_and_collide() if you want to make your own character physics system. Just use move_and_slide() if you are a beginner.