# Math in Unity : Dot Product (Part I)

Let’s continue our “mathematical” journey talking about the DoT Product.
First, WHAT IS THE DOT PRODUCT?

# The Dot Product is the sum of the multiplication of the components of a Vector.

In mathematics the written formula is this: The small square between the v and the w is the mathematical symbol of the Dot

Let’s take an example to better understand:
if we have two Vectors V (3, 9) and W (2, 7), applying the Dot formula the result is this:

# Math in Unity : Vectors (Part VIII)

Today we finish this little test, maybe I went too far even considering that these are basic notions.

Let’s get back to us.
As I said, to try to make everything work with our new methods we still have to make a few small changes.

In my script I have…

# Math in Unity : Vectors (Part VII)

Now let’s move on to Distance ()
Inside we pass two vectors, and calculate the distance.
The formula to be applied is the one seen in the last article, therefore

we will need the sum of

# then, the square root of the result

Let’s put it into practice!

First we calculate the difference between all points.

We…

# Math in Unity : Vectors (Part VI)

Now let’s try to code everything we’ve seen.
We will use a new Unity Class, called MATHF, which contains, as the word itself says, the mathematical part that we will need.

To have some fun, we will write some formulas ourselves and use MathF just to make testing easier.

This…

# Math in Unity : Vectors (Part V)

Now things get a little more interesting.
In the previous article we saw that with this type of code, the two sprites arrive at the same instant.

The question in this case is:
how can we give the same speed of movement to both sprites?

At present it does not…

# Math in Unity : Vectors (Part IV)

We have seen that by calculating the Vector v and adding it to our position, our sprite (in the Update ()), moves at a constant speed and stops exactly above the circle.
Everything good. …

# Math in Unity : Vectors (Part III)

In the previous article we used a speed variable to give our sprite a “speed”.

In that case, multiplying the Vector by a value, its DIRECTION will always remain the same, but its LENGTH will change (MAGNITUDE).

If our Vector were (1f, 1f), multiplying it by a number greater than…

# Math in Unity : Vectors (Part II)

Now let’s do a couple of practical examples on how to move our sprite.
I created a simple script called SpriteMove

For example, if we had a Vector 0.5f, 0.5f, 0

# Math in Unity : Vectors (Part I)

Before we move on, we need to understand this :
what is a Vector?

If I said that a Vector is a point in a Cartesian plane, would that be right?

For example, if in any 2D project I create a sprite, and put it in this position:

# Math in Unity : create a “graphic grid” with Cartesian Plane and Line Renderer (Part II)

As for the second problem, we should calculate some sort of “offset” and draw the lines based on that offset multiplied by the size of the grid.

For example: if we have our dimension of 13, our offset will be, in this case, 160 divided by 13.
Remember: our size… ## Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!