Move_and_slide() isn't working because the tutorial I was following was from godot 3

Godot Version

Godot 4

Question

How can I make the move and slide function work?

extends CharacterBody3D

const moveSpeed = 50
const turnSpeed = 180
const gravity = 98
const maxFallSpeed = 30
@onready var anim = $AnimationPlayer

var yVelo = 0
var grounded = false

func _physics_process(delta):
var moveDir = 0
var turnDir = 0
if Input.is_action_pressed(“Forwards”):
moveDir += 1
if Input.is_action_pressed(“Backwards”):
moveDir -= 1
if Input.is_action_pressed(“Leftwards”):
turnDir += 1
if Input.is_action_pressed(“Rightwards”):
turnDir -= 1
rotation_degrees.y += turnDir * turnSpeed * delta
var moveVec = global_transform.basis.z * moveSpeed * moveDir
moveVec.y = yVelo
move_and_slide()

Everything else is working but the movement

Follow a tutorial that uses the same version you are using.

If you are a new user to the engine, it’s better to start with the Getting Started part of the documentation here Introduction — Godot Engine (stable) documentation in English it will teach you how to use the editor, the concepts of Godot, and how to structure 2 small games one in 2D and another in 3D.

1 Like

Since move_and_slide() no longer accepts input parameters, set velocity (which is already defined in CharacterBody3D) instead of createing a new variable moveVec.

I’ve already done spme basic stuff but wanted to follow this tutorial in particular it’s not a general movement tutorial

Thank you