All Questions

Community

J
Jackie JJ

why don't we just always normalize move_direction?

Why don't we just always normalize move_direction? Why is it necessary to check the length first?

Also sneaking in a second question here:

	var input_direction: = get_input_direction()
	
	var move_direction: = input_direction

This step looks a bit redundant to me. Why don't we just do:

	var move_direction: = get_input_direction()

Is it necessary to keep the raw input direction? Or is this just about style?

  • Nathan Lovato replied
    Solution

    Here are the answers to your two questions:

    Why don't we just always normalize move_direction?

    Normalizing vectors makes their length 1.0. With keyboard input it works well but with joysticks and analog movement, using Input.get_action_strength, calling that function can lengthen the vector and make the character move at the same speed regardless of how far you're pushing the joystick.

    About the redundant line of code.

    This line changes by the end of the course. It's a small detail, probably at some point in the project's lifetime we used both values separately, or it was to show that the input direction and the move direction are different values with different meanings.