Popular Post Skillsbo Posted December 10, 2020 Popular Post Share Posted December 10, 2020 (edited) Hopefully this will be a complete tutorial in vectors within vanilla Skript (might add onto this with Biosphere stuff) Terms you will learn (definitions of each one will be in the tutorial) : Pitch and yaw Vector Magnitude Normalization Location Velocity Basic arithmetic Dot product Cross product Pitch and yaw Pitch and yaw define the Cartesian rotations in Minecraft. Yaw is the horizontal rotation and pitch is the vertical rotation, they are used to describe your facing direction (rotation). Minecraft displays your yaw going from 0 (south) to 180 (north), then -180 (north) back to 0 (south) And it displays your pitch going from 90 (looking down) to -90 (looking up) Now how is pitch and yaw related to vectors? Vectors Vectors are a way to describe both direction and magnitude, they do not describe location. Imagine vectors as an arrow in 3D space, the head of the vector is the tip of the arrow and the tail is the longer part. The head you can think of as "the direction that the vector is facing or heading" and you can think of the tail of the vector as how "strong" the vector is or the magnitude of the vector. You can create a basic vector from the yaw and pitch using the following code set {_v} to vector from yaw 0 and pitch 0 or from individual X, Y and Z components with set {_v} to vector(x, y, z) Magnitude Magnitude is the "length", "force" or "strength" of a vector, which you can think of as the length of the tail. It describes how long it is which is used to describe how long the vector is. Also magnitude/length is independent of direction (I know it's a great definition, if you don't get it now it will be made more clear soon) You can set the length of a vector using the following line set (standard|vector) length of {_v} to 5 and you can get the length with (standard|vector) length of {_v} Normalization Normalization is the way of taking a vector from its original length and making it 1. Length is independent of direction, so you can change the length all you want and its direction will not change. You can normalize a vector in 2 ways set {_v} to normalized {_v} # or set (standard|vector) length of {_v} to 1 Locations As stated earlier, vectors describe both direction and magnitude and not location, but they can be used to offset locations (offsetting a location by a direction). Think of offsetting like taking the vector, putting the tail at a location, and then wherever the head is is where the resulting location will be (and this is where magnitude also comes in, it will be how far the offset location is from the original location) You can offset a location by using [set {_loc} to] {_loc} (~|offset by) {_v} Velocity Since vectors describe both direction and magnitude, they are used to describe the velocity of entities or objects. Velocity is the speed of something in a given direction (wow it's like its almost the same definition of a vector). You can get the velocity of something using velocity of %(player|entity)% and you can set the velocity of something with set velocity of {_something} to {_v} # or set velocity of {_something} to vector(0, 1, 0) Vector Arithmetic Just like doing basic math with normal numbers (like 5 + 5 = 10), we can do basic math with vectors (notice the double signs). # Addition set {_v} to {_v} ++ {_v2} set {_v} to vector(1, 2, 3) ++ vector(4, 5, 6) # Subtraction set {_v} to {_v} -- {_v2} set {_v} to vector(1, 2, 3) -- vector(4, 5, 6) # Multiplication set {_v} to {_v} ** {_v2} set {_v} to vector(1, 2, 3) ** vector(4, 5, 6) # Division set {_v} to {_v} // {_v2} set {_v} to vector(1, 2, 3) // vector(4, 5, 6) Just in case you wanted to know what's going on behind the arithmetic, they are just doing the operations between the X, Y and Z components like this (addition for example) : # Addition vector(1, 2, 3) vector(4, 5, 6) + _______________ vector(5, 7, 9) Dot Product Doing the dot product of 2 vectors will return a number between 0 and 1 based on how similar 2 vectors are regardless of magnitude (0 meaning facing away and 1 meaning they are the same direction). You can get the dot product of 2 vectors using {_v} dot {_v2} Order of the vectors does not matter The image below outlines 3 examples of dot product with 2 vectors (magenta and light blue) and what it would return Cross Product Cross product is used to find the vector perpendicular to 2 other vectors crossing a plane Vector Rotations You can also rotate vectors around other vectors and vectors around the global X, Y and Z axis Rotating a vector along one of the global axes can be done using the following code # Rotating {_v} around the global x axis by 90 degrees rotate {_v} around x-axis 90 Which will look something like this And you can also rotate a vector around another vector using # Rotating {_v} around the direction of {_v2} by 90 degrees rotate {_v} around {_v2} by 90 Which will look something like this ({_v} is the light blue vector and {_v2} is the magenta) Miscellaneous Stuff (stuff not in other sections) Vector Yaw and Pitch You can get and set the yaw and pitch of a vector using the following (note that when setting the vector length will be set to 1) # Get vector yaw of {_v} # Set set vector yaw of {_v} to 15 X, Y and Z Components You can get and set the individual X, Y and Z from vectors using the following (note when setting, the vector length is subject to changing) # Get x of {_v} # Set set x of {_v} to 15 Vector Between Locations You can get a vector from 2 locations using the following (it will return a vector from the first location facing the second with the length equal to the distance between both locations) set {_v} to vector from {_l} and {_l2} Angle Between 2 Vectors You can get the angle between 2 vectors (their tails) using the following set {_a} to angle between {_v} and {_v2} And that would look something like this (assuming the vectors are perpendicular like shown) Usage Example (guns) The following script is an example of a use for vectors in Skript on right click with cake: set {_l} to location of player set {_v} to vector from yaw player's yaw and pitch player's pitch loop 40 times: set standard length of {_v} to loop-value / 2 set {_pewpew} to {_l} ~ {_v} kill all players in radius 1.5 of {_pewpew} where [input is not player] # show some epic particles at {_pewpew} To break it down, basically we store the location of the player, then we create a vector from their rotation, then we loop and increase the length of the vector and finally we offset the player's location by the vector and then bonk any players near the "bullet" that are not the player that initially shot Edited December 11, 2020 by Skillsbo 13 4 1 Link to comment Share on other sites More sharing options...
notminehut Posted December 11, 2020 Share Posted December 11, 2020 Awesome Tutorial! 1 1 Founder - Minehut.xyz The leading Minehut support website. We aim to provide top quality tutorials, provide answers to top questions, and help in any way we can. Our site is community driven, and we will continue to make it better and better. Support | 28/08/20 -13/09/20 Senior Support | 13/09/20 - 19/10/20 Link to comment Share on other sites More sharing options...
Pryzmm Posted December 11, 2020 Share Posted December 11, 2020 aRe wE aBlE tO mOvE pLaYeR'S liMbS? Owner of Lifestealed, Labs, Encore, UNOfficially and Observed OG [VIP] 12/26/20 - 10/27/2021 OG [PRO] 12/27/21 - 11/18/2022 OG [LEGEND] 11/18/2022 - 3/14/2023 [DEFAULT] 3/14/2023 - 5/8/2024 [MOD] 5/8/2024 - Present Link to comment Share on other sites More sharing options...
UntitledGoose Posted December 12, 2020 Share Posted December 12, 2020 3 hours ago, AgentGamerPro said: aRe wE aBlE tO mOvE pLaYeR'S liMbS? in Garry's Mod yeah 1 VIP since January 7th, 2020 Support since September 19th, 2020 Helper since November 3rd, 2020 Moderator since March 8th, 2021 Link to comment Share on other sites More sharing options...
_Tarna_ Posted December 12, 2020 Share Posted December 12, 2020 Cool tutorial. I've never used vectors in skript. Discord - tarna256 In-game name - _Tarna_ Website - https://tarna.dev Paste Site: https://paste.tarna.dev --------------------------------------------------------- [VIP] - 7/27/2020 Community Support - 7/8/20 - 11/3/20 Helper - 11/3/20 - 2/21/21 Moderator - 2/21/21 - 5/17/21 - 5/17/21 - 12/20/22 Moderator - 12/20/22 - now --------------------------------------------------------- Link to comment Share on other sites More sharing options...
Sh0ot Posted December 19, 2020 Share Posted December 19, 2020 Ive used this tutorial multiple times and its helped me alot. Thanks for this. 1 Link to comment Share on other sites More sharing options...
Name Posted December 21, 2020 Share Posted December 21, 2020 God: Creates Skillsbo Skillsbo: Creates vector tutorial God: 2 Whoops, this account shouldn't exist. Link to comment Share on other sites More sharing options...
Bonnie20402 Posted February 8, 2021 Share Posted February 8, 2021 You just helped me a lot dude Link to comment Share on other sites More sharing options...
Untreated Posted February 8, 2021 Share Posted February 8, 2021 Topic Locked. Please don't reply on month-old inactive threads (necro-posting). 𝚄𝚗𝚝𝚛𝚎𝚊𝚝𝚎𝚍 𝔻𝕚𝕤𝕔𝕠𝕣𝕕: @𝕌𝕟𝕥𝕣𝕖𝕒𝕥𝕖𝕕#𝟘𝟘𝟘𝟙 News & Updates • Rules • Helper Application Reports • Appeals 𝚂𝚝𝚊𝚏𝚏 𝚘𝚗 𝙼𝚒𝚗𝚎𝚑𝚞𝚝 𝚜𝚒𝚗𝚌𝚎 𝙹𝚞𝚗𝚎 𝟹𝟶𝚝𝚑, 𝟸𝟶𝟸𝟶 Link to comment Share on other sites More sharing options...
Recommended Posts