O'Reilly logo

iOS Game Programming Cookbook by Bhanu Birani, Chhavi Vaishnav

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using vectors

We will be using vector math frequently when designing the AI for our games. Vectors are used everywhere, from calculating which direction a game agent should shoot its gun in, to expressing the inputs and outputs of an artificial neural network. You should know them well.

Let's take a point P as follows:

P = (x, y)

A two-dimensional vector looks almost the same when written, as follows:

V = (x, y)

However, although similar, a vector represents two components: direction and magnitude. The right-hand side of the following diagram shows the vector (9, 6) situated at the origin:

Using vectors

The bearing of the arrow shows the direction of the vector, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required