How to manage movement in a "zero g" enviorement, where there is no frame of reference?

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)

Many games work with “jump for up” and “crouch for down” ideas. You will have to find some kind of additional input method anyhow.

But I have also seen special keys like “R”/¨Q" for up and “F”/“E” for down, etc. Even more options, if you plan with controller input.

In the end it does not really matter what it is, you just need input for additional movement :slight_smile:

That is not my problem, I know how to code in new inputs but making the player go “up” relative to their rotation is the problem.

This code already moves relative to the player’s rotation, that’s what basis * input does for you. To go up and down you only need to add the y component of the Vector3 instead of 0.

You do state in the first post that coding inputs is the problem, you can use Input.get_axis to fill in the last axis.

var input_plane := Input.get_vector("moveleft", "moveright", "moveforward", "movebackward")
var input_vertical := Input.get_axis("movedown", "moveup")

var direction := basis * Vector3(input_plane.x, input_vertical, input_plane.y)