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?

Have you tried not multiplying by the basis? I'm no expert but it seems that using only local coordinates should be enough.

    axolotl Hm. No I have not done that yet. Let me try that. I honestly don't even know what "basis" even means. I get the idea of using local coordinates but I don't know what using the basis of coordinates means.

    I will show the results of doing that when I implement them

    axolotl It didn't help. Removing the basis part of the code made it so the player wouldn't move unless they jumped, but they would only jump super slowly to the left no matter what directional key I was pressing (W, A, S, D).

    I modified my own controller and couldn't figure out the problem. Your code looks correct to me. I have a similar setup:
    movedir: var movedir: Vector2 = Input.get_vector("left", "right", "forward", "back")
    Its already normalized for you, but if I add an extra normalization it doesn't break.
    wishdir: var wishdir: Vector3 = transform.basis * Vector3(control.move.x, 0, control.move.y)
    If I try using global_transform.basis and/or another normalization doesn't break.

    wish_dir.y is 0 so you can do self.velocity = wish_dir * speed but again my code didn't break by doing it by each component.

    Its interesting that when you remove the basis part from your code, it does that. When I remove it on my end, it turns "left right up down" into "west east north south" ie character rotation doesn't change movement direction.

    Maybe it's a problem with the scene that my character controller is attached to?

    Or maybe I could just send the entire script for the character controller. What I sent was the movement code, but the script is huge with other lines of code for making the weapons work, making the ability to collect ammo and guns work, and dashing to work (dashing like in Mega Man X or DOOM Eternal).

    5 days later

    Sorry I didn't see the reply, if you want to upload the whole thing I'll take a look.