"normalized()" function on a FPS game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rubin

Hello, I’m new to Godot Engine and also this Q&A.

I’m studying 3D game development and made a simple FPS controller with the help of YouTube tutorials and Godot documentation, but I’m still having a problem:

I use a Vector3 to determine the direction of the player like that:

if Input.is_action_pressed("move_forward"):
	direction -= transform.basis.z
if Input.is_action_pressed("move_backward"):
	direction += transform.basis.z
if Input.is_action_pressed("move_left"):
	direction -= transform.basis.x
if Input.is_action_pressed("move_right"):
	direction += transform.basis.x

Some tutorials said I needed to use direction.normalized() to prevent the player from moving faster when pressing different movement keys (like forward + left for example) but the problem is that direction.normalized() don’t make any difference to my game. I tested it:

print("Before normalized: " , direction)
print("After normalized: " , direction)

Both print() commands give the same direction vector, meaning that direction.normalized() didn’t change any value. Is there a better way to prevent the player from moving faster while pressing different movement keys?

:bust_in_silhouette: Reply From: kidscancode

That’s because you’re not using the result of normalized()

direction = direction.normalized()

Thanks! It helped a lot!

Rubin | 2020-08-30 10:55