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 the variable v for Vector, but it is better to change the name to direction, to avoid confusion.
We have a _direction and we want to Normalize it.
What we need to do is simply go to the Update() and transform our direction like this:
P.S. I left the other piece of code commented out in case you want to see the difference.
Before making this change I had set the speed to 0.01f, now that the Vector is Normalized, I added the Time.deltaTime and I slightly increased the speed, precisely to 4f;
If we do a test, we see exactly what has changed
We now have the exact same speed for both sprites, but having normalized the Vector, the furthest sprite will obviously take longer to get to the circle.
I hope these articles will be useful to you, but before I leave you I would like to clarify one thing:
In the end we have done nothing but recreate functions that basically already exist, but we directly implemented the mathematical formulas for our purpose.
In the next articles we will see other very important things like DoTProduct, CrossProduct, Rotations, and much more!