I
Irisss_54

Why don't define velocity ?

As the tutorial shows, we define velocity at the very top as velocity: = Vector2.ZERO, and originally, we say velocity = direction * max_speed. However, after we add desired velocity, we subtract velocity from it without stating velocity = direction* max_speed. How would the computer know then if we don't give the variable "velocity" any calculation except just a Vector2.ZERO? 


  • Nathan Lovato replied

    we say velocity = direction * max_speed

    We make that calculation in a separate variable named desired_velocity, so this does not affect the velocity variable.

    In this lesson, we add something (steering_vector * drag_factor) to the velocity variable each frame depending on the player's input. Because we add something to the velocity variable, even though it starts at Vector2.ZERO, it changes after that, which is why the ship can move.

    Does this help clarify how this works?