Attention | Topic was automatically imported from the old Question2Answer platform. | |
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
move_and_slide(velo)
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