Godot Version
4.6.1
Question
I’ve been just starting to learn Godot and have been interested in making an FPS game, one that takes place in zero-g. I’ve followed a few tutorials online about setting up controls for the player, making them go where they are facing. However since many of these tutorials are for games where the player experiences gravity and therefor is always level with the ground, I’ve had issues coding in vertical movement.
While my character can move on the X and Z axis, they can not move up or down. I know how to make the player move on the global Y axis, the problem is figuring out how to make it work in relation to the rotation of the player. Since I have the player floating, I want the player to move up relative to their character’s rotation then the global rotation. However currently I’m using the “Input.get_vector()” method which is only Vector2 and so can’t help with vertical movement. So is there a way to have the character move on all three axis relative to itself? I’m sure there is, but I don’t know how to do it.
My current movement code is this:
# gets avg of WASD inputs, otherwise can only move one at a time, no up or down movement
var input_dir = Input.get_vector("moveleft", "moveright", "moveforward", "movebackward")
# go where we are facing
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
# move
if direction:
velocity.x = direction.x * PLAYERVEL * playervelmultiplyer
velocity.z = direction.z * PLAYERVEL * playervelmultiplyer
else: # slow to stop if no inputs
velocity.x = lerp(velocity.x, direction.x * PLAYERVEL * playervelmultiplyer, delta * 1.0)
velocity.z = lerp(velocity.z, direction.z * PLAYERVEL * playervelmultiplyer, delta * 1.0)