Improve my player movement script please

Godot Version



I followed a tutorial from LegionGames about making a FPS controller. I went mildly off the rails with my own naming conventions and a few recommended improvements from the comment section.

Can someone take a look and let me know if anything can be improved further, either performance wise or making everything feel nice and fluid?

extends CharacterBody3Dvar speed@export var sprint_speed = 4.0@export va -

if direction:
			velocity.x = direction.x * speed
			velocity.z = direction.z * speed

You could vectorize this

if direction:
			velocity = direction * speed

After this your gravity velocity will be zero. You could move the gravity code after this or just get rid of the gravity code. you shouldn’t need to manually add gravity.

Maybe you could temporarily stor the y portion while you modify the input velocity then add the y portion back in.

Not at my computer yet! Will definitely try the first bit and remove gravity though. Is this more for cleaner code or do you think it has any other improvements to it?

And unfortunately, not sure I understood the second part about storing the y portion.