Understanding the Origin
On the first page I said that every vector has its starting point at the origin. Now initially this may cause some confusion. In almost all cases we are not at the origin. It would suck only being able to use vectors around the origin in Minecraft at (0,0,0)
. Luckily for us we can use operations like adding, subtracting, multiplying and diving on vectors and are therefore able to construct what I call offset vectors. The general rule for any vector math will always be:
Do vector math around the origin.
Add in the offset vector.
For example if you want to do something near the players location, the vector from that location is the offset vector.
If we don't stay around the origin we may see strange results when rotating vectors (which will happen a lot, once we get there).
Incase you're inexperienced with vector addition I highly suggest you check out the brief vector addition tutorial before reading the following example.
Suppose we have a vector referring to the players location and a vector for the direction the player is looking at. What we want to do is find the vector in the opposite direction of the direction the player is looking at.
You might assume it looks like the following.

However that's not the case and more often than not, not useful to work with (but useful to imagine). In reality the orange dir
vector sits at the origin. From there on it's really easy to get the opposite vector (multiply it with -1
). After we did the math operation we can add it back to the location vector.

The first part of the animation is not necessary. It's more of a reminder to always shift to the origin before doing operations.
Now that you learned the basics you're ready to take a deep dive into the API methods provided by Spigot.
Last updated