• Hey! Register here to create your account, engage with the community, and talk about what is new!

Vectors Guide

RyanLand

Well-known member
Overlord
Joined
Sep 6, 2020
Messages
60
Reaction score
39
Vectors

---
Vectors were introduced in 5.3. They may be diffiult to understand at first, but they can be extremely useful!

Before jumping into it, if you're familiar with real life vector maths, yep, these are exactly like that.

---
What is a vector?
A vector has 3 components: X, Y and Z. You can see vectors as a line from point A to B (basically, a vector is direction and magnitude combined). A will be (0,0,0) in this example. If our vector is <3,3,3> the vector is a straight line from (0,0,0) to (3,3,3). To easily visualize this, set a vector and left-click while holding it.

ySb58QH.png


---
Actions

We're going to go over all vector-related actions individually here.

- Add Vector to Location
We can use vectors to move locations with this action. It will calculate the sum of each component.
Guess what will happen if we add the vector <3,5,2> to the location (6,-3,4). The result will be (6+3, -3+5, 2+4), or (9,2,6).

- Add Vectors
Similar to above action, except with vectors. Example:
<3,6,4> + <1,3,-2> + <5,2,7> = <3+1+5, 6+3+2, 4-2+7> = <9,11,5>.

- Align Vector
Sets all components to 0, except for the highest absolute one, also favors the last components. Examples:
AlignVector(<1,2,3>) = <0,0,3>
AlignVector(<-5,4,-3>) = <-5,0,0>
AlignVector(<-5,6,-3>) = <0,6,0>
AlignVector(<1,1,1>) = <0,0,1>

- Get Vector Component
Gets one of a vector's components (X, Y or Z). Example:
GetVectorComp(<1,2,3>, Z) returns 3.

- Get Vector Length
Gets the magnitude (or length) of a vector. Basically the distance from point A to B. Example:
Our vector is <3,0,0>. We can see this as a line from (0,0,0) to (3,0,0). The distance between these points will be the result of this action, which is 3.

(Advanced) Get Vector Length also has a tag to change the result of the action. Setting it to Length Squared will partially use the formula for calculating a vector's magnitude. It will not use root (√) on the expression. Example:
GetVectorLength(<1,0,1>, Length) = 1.414 (DiamondFire has a decimal limit of 3 per number)
GetVectorLength(<1,0,1>, Length Squared) = 2

- Multiply Vector
Multiplies each of a vector's components by a scalar. Example:
<2,5,3> * 3 = <2*3, 5*3, 3*3> = <6,15,9>.

- Set to Vector
Sets a vector to the components provided (X, Y and Z), OR use a direction text. Direction Example:
SetVector('north') = <0,0,-1>

- Set to Vector Between Locations
Remember the line example? Here we're setting one. It will set to the vector that has a line that perfectly fits from point one to point two. If we have location one (0,1,0) and location two (2,3,4) the vector would be <2,2,4>.

- Shift Location on Vector
Shifts a location based on the direction of a vector. Example:
ShiftLocOnVector((0,0,0), <1,0,0>, 3) = (3,0,0)

- Subtract Vectors
Subtracts each of a vector's components. Example:
<8,6,3> - <1,4,2> = <8-1, 6-4, 3-2> = <7,2,1>.

Advanced Actions
These are actions that are more advanced linear algebra, and I don't think these will be used much in DiamondFire, and as such, is not worth the space. This is why I'm going to link you to people that are much better at explaining.

- Reflect Vector
https://en.wikipedia.org/wiki/Reflection_(mathematics)

- Rotate Vector Around Axis
https://en.wikipedia.org/wiki/Rotation_matrix

- Rotate Vector Around Vector
https://en.wikipedia.org/wiki/Rotation_matrix

- Set to Cross Product
https://en.wikipedia.org/wiki/Cross_product

- Set to Dot Product
https://en.wikipedia.org/wiki/Dot_product

---

Phew, that was a lot of information. Still have questions left? Simply reply to this thread!
 

Vulcano

Forum adept
Overlord
Joined
Sep 11, 2020
Messages
251
Reaction score
65
Great tutorial, I hope players read this when vectors come to main nodes, as it will surely help those who are struggling!
 

Prox

Moderator
Moderator
Joined
Sep 9, 2020
Messages
384
Reaction score
31
I am dark mode friendliness insert gender neutral term. I am here to inform you that the arrow in the graphic provided is not dark user friendly. While visible, it may be hard to see for some users.
1607004134107.png
Do fix, @RyanLand.
 

S4nders

New member
Joined
Oct 7, 2020
Messages
11
Reaction score
19
"Rotate Vector around Axis" and "Rotate Vector around Vector" are two of the most important Vector actions. They are worth exploring and explaining to others, and are not nearly as advanced as the other advanced vector actions.
 

Oasher

New member
Joined
Sep 12, 2020
Messages
10
Reaction score
1
I dont really get the difference between a location and a vector other than its easier to subtract vectors than locations and similar stuff to that.
 

stinkey

Forum adept
Joined
Sep 8, 2020
Messages
225
Reaction score
74
I dont really get the difference between a location and a vector other than its easier to subtract vectors than locations and similar stuff to that.
Locations are locations, vectors are directions with magnitude. Vectors are also different from pitch/yaw as 1, they are easier to use when calculating physics and stuff and 2, they have a length and are a ray while pitch/yaw are just a direction without any magnitude.

Vectors are cool because lots of directional stuff and interacting forces can be simulated more easily with vectors than pitch/yaw. In a generic DF game, you probably won't find them other than changing the velocity of an entity or raycasting, but they can be complex and unlock lots of more complicated stuff (if you are going to make a physics engine or mob pathfinding different to Minecraft's original physics and AI)
 
Top Bottom