What can I replace move_and_slide() with to get the same result?

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

I followed this code from an old tutorial but eventually learned that move_and_slide() doesn’t take any arguments as of Godot 4.0. What could I replace it with or how can I write this differently?

extends CharacterBody3D

const MAXSPEED = 30
const ACCELERATION = 0.75
var inputVector = Vector3()
var velo = Vector3()

func _physics_process(delta):
	inputVector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	inputVector.y = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
	inputVector = inputVector.normalized()
	velo.x = move_toward(velo.x, inputVector.x * MAXSPEED, ACCELERATION)
	velo.y = move_toward(velo.y, inputVector.y * MAXSPEED, ACCELERATION)
	rotation_degrees.z = velo.x * -2
	rotation_degrees.x = velo.y / 2
	rotation_degrees.y = -velo.x / 2

You can replace move_and_slide() with move_by() to get the same result. move_by() allows you to move an object in a particular direction by a certain amount of units. This will allow you to achieve the same result as move_and_slide() without having to calculate the speed or direction of the object.

Asidert | 2023-04-26 04:18

:bust_in_silhouette: Reply From: Game_gulf

I leave a working code, you can adjust it yourself

func _physics_process(delta):

#	if not is_on_floor():
#		velocity.y -= gravity * delta * speed
	if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left") or right1 ==true or left1 == true:
		if Input.is_action_pressed("ui_right") or right1==true:
			velocity.x = lerpf(velocity.x, right_point, 0.4)#velocity.x = left_point * +delta * 25 
		if Input.is_action_pressed("ui_left") or left1 == true:
			velocity.x = lerpf(velocity.x, -right_point, 0.4)
		velocity.x = move_toward(velocity.x,0,speed) # saga yada sola dönünce aptalca kaymaması için
	velocity.z = speed * -delta * speed *3