Back to Physics in Simulations
IntermediateAdults

Vectors for Game Development

In physics and game development, a **vector** is an object that has both a magnitude (length/size) and a direction. We use vectors to represent things like position, velocity, and acceleration.

A 2D vector has two components: an x component and a y component. You might see it written as (x, y).

**Position:** A vector from the origin (0,0) to a point in space. The vector (10, 20) represents the point 10 units right and 20 units down.

**Velocity:** A vector representing the change in position over time. A velocity vector of (5, -2) means the object moves 5 units right and 2 units up every second.

**Vector Math:**
- **Addition:** To add two vectors, you add their components. (2, 3) + (4, 1) = (6, 4). This is used to combine forces or velocities.
- **Scalar Multiplication:** To multiply a vector by a single number (a scalar), you multiply each component. 3 * (2, 5) = (6, 15). This is used to scale forces or speed.

Understanding vectors is essential for creating movement and interactions in any physics simulation.

Vector Addition

Create a function `add_vectors` that takes two vectors (represented as dictionaries) and returns their sum as a new vector.