It works in the same way it does in 3.x, but the function's parameters are now properties of the body.
velocity
is now a node property, along with up_direction
, etc. And move_and_slide()
now takes no arguments.
So, the following code for basic movement in 3.x:
extends KinematicBody
var gravity = 10.0
var speed = 3.0
var velocity = Vector3.ZERO
func _physics_process(delta):
velocity.y += gravity * delta
velocity.x = Input.get_axis("ui_up", "ui_down") * transform.basis.z * speed
velocity = move_and_slide(velocity, Vector3.UP)
Would become
extends CharacterBody3D
var gravity = 10.0
var speed = 3.0
func _physics_process(delta):
velocity.y += gravity * delta
velocity.x = Input.get_axis("ui_up", "ui_down") * transform.basis.z * speed
move_and_slide()
See https://docs.godotengine.org/en/latest/classes/class_characterbody3d.html and the default built-in CharacterBody3D script for details.