# Is speed and direction generally combined into one vector, or separated into two?

For example, for a game (in my case a 2D top-down one), there could be advantages to doing so. For example, whenever you want to change an entity's direction, you just assign entity.direction = unitVector and bam, the direction is changed.

Similarly, if you want to apply a powerup that increases their speed, you just do entity.speed += 5, since it's a scalar value.

However, I also see advantages to keeping them combined. For one, a vector is already the combination of magnitude and direction, so it feels natural to combine into a single value. Secondly, it prevents desync. For example, if you have some sort of function that modifies the an entity's velocity, you have to constantly check whether you're dealing with direction or speed, and also be sure to update both values independently, which can be confusing.

How is this generally handled in the majority of cases? Are they combined, or not? And if they are combined, what are the recommended ways of changing just the speed, or changing just the direction of this combined vector value?

Take for example the vector $$\ \vec{v} = \begin{pmatrix} 1 \\ 1 \end{pmatrix} \$$ . You can extract the magnitude ($$\ \sqrt{2} \$$ ) and the direction ($$\\begin{pmatrix} 1 \\ 1 \end{pmatrix} \$$, 45° assuming 0° is horizontal pointing to the right).
• Yeah, getting the magnitude and direction seems easy enough. So does multiplying the speed by a scalar. But I'm not exactly sure how to change the direction. It's just a 2D vector in a 2D top-down game, so how would I do that then? That is, if my current vector is x: 3, y: 3 (so the speed would be 4.2 with that, I think?), how would I then change the speed to be the same in the southern direction? Just multiply 4.2 by the southern unit vector, I suppose? So just extract the magnitude and then multiply it by the new direction's unit vector? – Ryan Peschel Mar 29 at 22:22