- Edited
Hello! So, I am trying to implement an FPS character controller into my game, and it’s being weird. The side-to-side movement works just fine, but for some reason when I try move moving forwards or backwards and then try moving side to side so I can go diagonal, I stop moving forwards or backwards.
Here is my code:
func _handle_air_physics(delta) -> void:
self.velocity.y -= gravity * delta
self.velocity.x = wish_dir.x * speed
self.velocity.z = wish_dir.z * speed
func _handle_ground_physics(delta) -> void:
self.velocity.x = wish_dir.x * speed
self.velocity.z = wish_dir.z * speed
func _physics_process(delta):
var input_dir := Input.get_vector("left", "right", "up", "down").normalized()
wish_dir = (self.global_transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if is_on_floor():
if Input.is_action_just_pressed("jump"):
self.velocity.y = jump
_handle_ground_physics(delta)
else:
_handle_air_physics(delta)
if is_on_wall() and Input.is_action_just_pressed("jump", true):
self.velocity.y = jump
move_and_slide()
This is what the bug looks like:
Can anyone help?