Let’s continue our “mathematical” journey talking about the DoT Product.
First, WHAT IS THE DOT PRODUCT?
In mathematics the written formula is this:
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:
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…
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
Let’s put it into practice!
First we calculate the difference between all points.
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.
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…
In this article we will slightly update the previous code.
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. …
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…
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…