YouTube2Text

Vector3 - Roblox Advanced Scripting #7 — Transcript

by BrawlDev · 4,435 words · 227 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hey thanks for stopping by we're going to be  introduced to a new data type that Roblox has
  2. 0:05provided for us called Vector 3 so pretty much  Vector 3 is a value that allows us to manipulate
  3. 0:12specific properties inside of our 3D World usually  with things that have to do with positioning a
  4. 0:18part inside of our world so it's definitely  a very powerful data type which is why we're
  5. 0:22going to be introduced to how to use Vector 3s  inside of our 3D world through scripting and so
  6. 0:28I basically whipped up like a little example here  with this part um so basically what should happen
  7. 0:33is something magical when I click this part um  what happens is when I click it then bro this
  8. 0:38part is just flying by it's just like sliding all  the way out to somewhere that's not close to me
  9. 0:45because this part does not love me um but yeah I  basically just constantly change the value of one
  10. 0:51of its positional values to go in this direction  uh Forever and Ever After I clicked on it so this
  11. 0:57is with the use of vector 3 and I'm going to  be showing you how to do this but before we
  12. 1:02start implementing Vector 3s I want you to really  understand how this all works and I'm going to do
  13. 1:08that by showing you an example all right let's  think about this for a minute so I'm in a game
  14. 1:12of Minecraft and I know it's kind of weird but  trust me it'll make sense Minecraft is a 3D game
  15. 1:18and it has a 3D world that has three directional  values that correlate to the location of where
  16. 1:25the player is inside of the game called The X Y  and Z coordinates and if you want to see these
  17. 1:30coordinates you have to press F3 on your keyboard  like this that shows a bunch of Statistics from
  18. 1:36of the world that you're currently playing but  we're mostly interested in the X Y and Z values
  19. 1:41on the left side so as you can see our X Y and  Z value are X being -16 our y being 63 and then
  20. 1:48our Z being 239 if we move around inside of the  workspace uh these values are changing accordingly
  21. 1:56to where we are inside of the world so if I move  in this Direction then it's increasing the x value
  22. 2:03um every time we move in this direction so this  is called the X Direction and if we move backwards
  23. 2:09then we're decreasing our number in the X uh Axis  or coordinate and now let's say we go this way
  24. 2:17this is increasing our Z value uh every time we  move forward inside of this direction but if we
  25. 2:23move backwards then it's going to continuously  decrease our zv value um the further we go
  26. 2:30backwards and the Y which is the which is the  second value like how high we are in the workspace
  27. 2:37right now so if I just fly up then you can see  that our yv value is constantly increasing and
  28. 2:44if I just drop back down then it goes all the way  back down to where we are um inside of the world
  29. 2:50so these are the three positional values um that  represents a vector 3 if you were to compare this
  30. 2:56to Roblox but it's essentially the same idea so  this was just something I wanted to show you um
  31. 3:02before we start implementing this stuff just so  that you can get a better understanding of what
  32. 3:07the heck of vector 3 value is it's pretty much  a vector that comprises of three values called
  33. 3:13the x value the yv value and the Z value that can  be used to change values of parts that are inside
  34. 3:21of our Roblox world not just with positions both  sizes and rotation and all of that sorts of stuff
  35. 3:28so that's what we're going to be doing in this  episode now that we understand it let me show you
  36. 3:31what a vector looks like inside of Roblox studio  so on the top right of the screen I don't know if
  37. 3:36you have this but this essentially shows us our  directional values with x y and z um to tell us
  38. 3:43where inside of Roblox Studio our three axes are  located so if we go this way then it's going to
  39. 3:50increase our x value if we go backwards it's  going to decrease our XV value and if we turn
  40. 3:55around this way then we increase our zv value by  going this way and of course the yv value it just
  41. 4:00it's basically determined by how high you are  versus how low you are so now let's translate
  42. 4:04that to a part when we insert it inside of studio  so let's go up here to model and hit part so with
  43. 4:11this part we can come down here to cframe and we  can see that there's a property called position
  44. 4:17um ignore this position that's inside of the  or origin category we're mainly focused on the
  45. 4:23C frame position so this one basically shows us  our X Y and Z coordinates just like in Minecraft
  46. 4:29so if we select this part uh select move and move  it in this direction it increases our zv value if
  47. 4:39we make it go back this way it decreases our  zv value and if we make the part go this way
  48. 4:44it decreases our x value and if we make it go  this way then it increases our x value and of
  49. 4:50course the same thing for the yv value increase it  goes up here and then just goes back down here so
  50. 4:54that's pretty self-explanatory we can even change  individual values of our X Y and Z position so
  51. 5:00we can make this five for example uh this just  makes it five and then for Z we can make it uh
  52. 5:0610 it goes this way so you get the basic idea  our position consists of three values X Y and
  53. 5:13Z that's basically contained inside of one data  type called a vector 3 and now I'll show you what
  54. 5:19it looks like in a script so what we're going to  do is on the right side let's click on the plus
  55. 5:24sign and at part and let's insert a script and  we're first going to make reference to our part
  56. 5:29which is going to be local part equals script.  parent and then what we'll do is we're going to
  57. 5:37change the position of the part when we run the  script inside of our game so currently right now
  58. 5:43our position is -12 0.5 And1 let's change it to  something different let's change the position when
  59. 5:51we run the script by saying part. position equals  and now you have to understand how to to actually
  60. 6:00create this new Vector value um and we will do  that by using a new Constructor and the way it's
  61. 6:07going to look is something like this we're going  to say Vector 3. new because we're constructing a
  62. 6:15new Vector 3 value full of three different numbers  put inside of here so we're going to say open and
  63. 6:21close parentheses and now inside of here we we're  first going to put in our our new x value which
  64. 6:28we're going to say 10 and then our new y value  which we'll just say three and then our new Z
  65. 6:36value which is going to be let's say 10 again so  effectively this is going to replace the parts
  66. 6:42position which is currently this value right here  -12 0.5 And1 to this new value which is going to
  67. 6:49be 10 3 and 10 so let's go to the game hit test  we're going to hit run because we don't need to
  68. 6:55play the game in order to see this and as you can  see the script ran and it CH automatically changed
  69. 7:01the position of this part when we ran this script  to change its position to this new value right
  70. 7:09here so to reiterate a vector 3 is a data type  that holds three numbers the x value the Y value
  71. 7:16and the Z value to change the position of this  part but Vector 3s can be used for other things
  72. 7:22other than positions so if we look more into this  part let's look at some properties that also have
  73. 7:28three values so for instance our size has an X Y  and Z our orientation also known as our rotational
  74. 7:36value has an X Y and Z so we can use Vector  3es for that and then some other complicated
  75. 7:41stuff like assembly linear velocity and assembly  angular velocity that also has X Y and Z values
  76. 7:47so anything that has three values that are  comprised of X Y and Z coordinates is deemed
  77. 7:52a vector 3 data type now let's do some Vector  operations and what I mean is adding subtracting
  78. 7:59multiplying and dividing uh like all those basic  operations with multiple vectors and I'll show
  79. 8:05you a really easy example for this one so if we  select our part I don't know if you noticed but
  80. 8:10and we have it selected to our move tool then it  automatically shows our x y and z-axis to be able
  81. 8:16to change the location of the part but now what  we're going to do is basically take the position
  82. 8:22of this current part and add a new Vector to it so  that it'll just move in a certain direction rather
  83. 8:29than having a whole new location um and we're  going to do that first by changing the position
  84. 8:36of this to something very easy to grasp so let's  just highlight this and make the position at the
  85. 8:45origin of 0 0 so we're going to select position  and we're going to and we're going to put in a 0
  86. 8:52comma 0 comma 0 and so that's going to be located  at the very origin let's take our our um spawn
  87. 9:00location and just move it a little bit so we can  see this part and now our and now our part is in
  88. 9:05the origin of the world but let's also move the  base plate down a little bit so that so that the
  89. 9:10part has room to be able to move freely without  being clipped through any parts so let's change
  90. 9:15the Y value of the base plate to 8.5 so now we  should be able to see the part freely over here
  91. 9:26uh with no issues let's also move this um spawn  location a bit over here okay now essentially what
  92. 9:31we want to do is take this part have its current  location which is 00 0 and add a number that goes
  93. 9:38in the Z Direction like let's say five five in  this direction so first what we're going to do is
  94. 9:46go to our script and let's delete this new Vector  3 value that we created and how we're going to
  95. 9:52change this position is by obviously getting the  parts position first so we're going to say part.
  96. 10:01position plus Vector 3. new and we want to just  change the Z value to wherever currently is + 5
  97. 10:14so what we're going to do is first put in our x  value which is going to be zero comma our Y which
  98. 10:20is also going to be zero and then finally our Z  value which is going to be five so basically we're
  99. 10:26going to take the parts position which is just 0  0 and then add that to a new Vector with 0 05 so
  100. 10:36in the end this will end up resulting in a new  Vector 3 position that is 0 05 so let's see what
  101. 10:45happens if we hit test and hit run we should see  that when the script fired it moved the position
  102. 10:54of this part to what it was at the beginning  which was 0 0 0 and then to 005 and the reason
  103. 11:03it looks like this is because we have the part  angered so it was impacted by gravity a little
  104. 11:08bit let me just anchor this part so that we can  really see the new Vector change so if we select
  105. 11:13the part again then as you can see our position is  now 005 because its original position before the
  106. 11:23script ran was 0000 0 and then we added a five  to the Z value to make it 0 0 five I hope this
  107. 11:32basic example made sense a little bit because  when we use vectors we are going to be using
  108. 11:38computations to get a new result from different  Vector values like adding vectors for instance
  109. 11:45and there's also another way of writing this too  instead of just reiterating part. position equals
  110. 11:49part. position plus Vector 3. new what we could  do instead is delete this first part and we can
  111. 11:56just put in a plus equals this BAS basically  means the same thing as the one we just had
  112. 12:01before where we basically take the current Parts  position and add a new Vector to that position
  113. 12:09and we should just get the same exact result it  it really comes down to preference which one you
  114. 12:13like to do more I'm just letting you know this is  also another way of just taking the current Parts
  115. 12:18position and adding a new Vector to it we can even  do this with subtraction and there's two ways of
  116. 12:23doing subtractions so the first way is just taking  part. position and then subtract equals Vector 3.
  117. 12:31new 005 so just to make this easier let's change  the syntax to part. position minus instead of what
  118. 12:42we had before so the part's position is going  to be whatever the position it currently is and
  119. 12:48then subtract that by our new Vector here now you  have to be careful that this is supposed to be a
  120. 12:55five and not a NE because we are subtracting this  Vector so if we have a five here this essentially
  121. 13:02means take the Z value and subtract it by five  so if we go into the game we should see that the
  122. 13:08zv value will go in the other direction so it  goes back here so our zv value is now ne5 and
  123. 13:16not five there's another way of writing this uh  we can actually do part. position plus Vector 3.
  124. 13:24new -5 and this should basically give us the same  result as subtracting a vector three of five so as
  125. 13:33you can see it basically did the exact same thing  as we did with subtraction except we kind of just
  126. 13:39flipped the signs around because as you know how  math works if you flip signs you can basically get
  127. 13:45the same result in this way if you prefer to do it  so I just wanted to let you know that that there's
  128. 13:50two ways of making this calculation and then of  course you have multiplication and subtraction
  129. 13:55which I hope you know how those two operations  work so so so the way multiplication works is
  130. 14:00we're going to replace this plus sign with an  aster so this represents uh multiplication and
  131. 14:06we're going to multiply the current Parts position  to whatever uh new value we have here for Vector
  132. 14:123 let's get rid of this zv value by putting in  a zero and let's change the x value to uh two
  133. 14:19so what it's going to do is it's going to take  the x value of this part which is zero and it's
  134. 14:26going to multiply it by two now what should happen  is that it's still going to be in the same place
  135. 14:33as it usually is because 0 * 2 is 0 so let's  actually change this position to one so that
  136. 14:39we can effectively see the multiplication that we  do with this part so it's a very small difference
  137. 14:45but as you can see our x value changed to two  because 1 * 2 is 2 so we effectively made that
  138. 14:51calculation and you can pretty much do the same  thing with division it's um basically a forward
  139. 14:56slash to represent division and you basically get  the idea I hope so far this is making sense to you
  140. 15:02because there is a bunch of math required when it  comes to Vector 3 values in due time the more you
  141. 15:08practice the more you'll definitely get better  at it so I believe in you but anyways we dealt
  142. 15:12with changing the position of this part but there  are other values we can change that uses Vector
  143. 15:183 values like size and rotation or orientation in  this case so let's change those values and so the
  144. 15:25way we change the size of a part inside of Studio  is by going to model and going to our scale tool
  145. 15:32and it's basically the same way with moving  except we can scale this part uh in whatever
  146. 15:38axes we want to scale the part to um whether that  be the x value the yv value or the Z value we can
  147. 15:45pretty much do the same thing and this also takes  in a vector 3 value so if we want to change this
  148. 15:51through a script we essentially do it the same  way we do with the position so let's go to our
  149. 15:56script and let's change the parts size size so  we're going to say part. size equals Vector 3.
  150. 16:06new and we can put in some value like four four  and four so it's going to change the size of this
  151. 16:14part to forward when we test the game so if we  test it then we should see that the part size
  152. 16:20have has been successfully changed to be 4X 4X 4  and we can even do the same thing with rotation
  153. 16:27as well what we can do here is drop a line and say  part. orientation equals Vector 3. new and we can
  154. 16:40say 25 0 25 let's see what that results in when  we hit run so as you can see the orientation or
  155. 16:52the rotation of the part has changed accordingly  to what we said it to do inside of our script so
  156. 16:58it's basically the equivalence of our rotation  tool so the red is our x value the the blue is
  157. 17:05our zv value and the green is our y value so it's  a bit more confusing and less intuitive for X Y
  158. 17:12and Z values for rotation so you're going to have  to be familiar with how uh rotational axes in
  159. 17:19orientation works with uh parts or models inside  of the game another thing we can do is multiply
  160. 17:25and divide a vector with just a number so in this  case what we can do is we can take the position
  161. 17:33of our part and just multiply that Vector value  by a number to then change every value that's
  162. 17:40in the vector 3 value and I'll explain to you  what I'm talking about but first let's change
  163. 17:45the base position of our part so we're going to  go down here and let's change this position to 1
  164. 17:540 and one and let's go to our script so let's  delete these two lines of code right here and
  165. 18:01the first thing we're going to do is say part.  position equals part. position and we're going to
  166. 18:10multiply this by number so we'll say times 5 you  can take a guess what's going to happen here but
  167. 18:16essentially it's going to take every value that's  in this Vector 3 which is 1 0 and one and multiply
  168. 18:24all the numbers by five so our x value is one so 1  * 5 is 5 0 * 5 is 0 and then 1 * 5 is 5 from that
  169. 18:34we're going to get a result of 505 When We Run the  game like so so if we select this part we can see
  170. 18:41that the new position is 505 because we took the  original position of the part which was 0 1 0 and
  171. 18:49then we multiplied all those values by five and so  that's how we got the result of this position we
  172. 18:56can even do the same thing with division 1 / 5 is  going to give us a pretty small number um so it's
  173. 19:03going to have a very small difference but let's  see this very small difference um in play so our
  174. 19:10parts should have a position of 0.2 because  1 / 5 is 1/ 15s and in and in decimal that's
  175. 19:190.2 so I hope that part makes sense to you we're  going to create a practical use case of vector 3
  176. 19:24values by creating a Teleport script whenever the  player joins the game let me show you how this is
  177. 19:29going to look so first thing we're going to do is  create a new part so let's go to model part and
  178. 19:36let's name let's rename this part to teleport part  let's even change the color of this too to Blue
  179. 19:45and let's move this over here now what we're going  to do is create a script inside of server script
  180. 19:50service like so and then what we're going to do  is create a player added event so game. players.
  181. 19:58player added connect function open parentheses  close parentheses enter the parameter here is
  182. 20:06going to be player one thing we have to do is  know how we can actually teleport our character to
  183. 20:14another position inside of the game so I'm going  to show you how we're going to do that right now
  184. 20:18if we open up workspace and go to our character  and open this up we can see that there's a prop
  185. 20:24there's a part here called humanoid root Parts  it's kind kind of hard to see the humanoid root
  186. 20:29part but essentially it's like an invisible box  that's surrounding our torso area much like our
  187. 20:36upper torso so we can actually see our upper  torso here but our humanoid root part is like
  188. 20:41this invisible part that basically connects all  of the attachments to our character together into
  189. 20:48one and so we're going to be changing the position  of this humanoid root part to the position of our
  190. 20:55teleport part in order to move our character from  where we currently are to that part over there so
  191. 21:02that's what we're going to be doing so now that  we understand that let's locate the humanoid root
  192. 21:06part by first making reference to the humanoid  root part so we're going to say local humanoid
  193. 21:13root part equals player. character and we're going  to wait until the player's character completely
  194. 21:22loads into the game so we're first going to say so  we're going to say colon wait for child so we're
  195. 21:29going to have the script wait until a humanoid  root part exists inside of the characters so in
  196. 21:35quotations we're going to say humanoid root part  and then down here we're going to say humanoid
  197. 21:44root part. position so we're going to modify the  position of the current humanoid root part equal
  198. 21:51to game. workpace do teleport part Doos so in  these two lines of code we're basically getting
  199. 22:04the humanoid root part from the player's character  and then we're going to change that position to
  200. 22:10the position of this teleport over teleport part  over here um after the player has joined the game
  201. 22:16so if we hit play okay so there's a little error  here um there isn't enough time for the script
  202. 22:22to wait until the player joins into the game so we  can either do this in two ways uh one is by adding
  203. 22:28a task. weight function or we can add in another  event that calls the character every time every
  204. 22:35time their character loads into the game or resets  so for the sake of Simplicity let's just add a
  205. 22:40task. weight to this event so we're going to say  task. wait and then we're going to wait 5 seconds
  206. 22:46before the script runs so let's go into the game  and hit play and after we wait about 5 seconds
  207. 22:51it's going to locate the characters humanoid  report and then we should be able to teleport just
  208. 22:55fine so as you can see our character did indeed  teleport to the part the part's position but then
  209. 23:02we kind of slid off a little bit because if we're  teleporting our player to the direct position of
  210. 23:08this part it's going to literally be inside of  this part so what we can do we can add a y value
  211. 23:14of five so that the player spawns right on top  of the part not in the part so we're going to go
  212. 23:21over here and let me just zoom out a little bit  and we're going to add in a new vector by saying
  213. 23:28plus Vector 3. new 0 comma 5 comma 0 so it's going  to take the teleport Parts position and add five
  214. 23:40to the height or the yv value so that the player  spawns right on top of it not inside of the part
  215. 23:46so let's go into the game and see our change after  about 5 Seconds it should spawn our character on
  216. 23:51top of the part not in the part so there you  go our teleport script should be working just
  217. 23:55fine I hope this introduction to Vector 3s served  you well um I'm not going to go over every single
  218. 24:01thing that Vector 3s have to offer because this  just serves as an introduction to get your foot
  219. 24:07in the door to be able to understand Vector 3s  for your future Roblox projects because Vector
  220. 24:133s they it's a complicated data type and it'll  only get more complicated from here so I highly
  221. 24:19encourage you to read the documentations for  Vector 3s maybe look up more tutorial guides
  222. 24:25from other YouTubers who've talked about uh Vector  3s as well so that you can really understand how
  223. 24:31you can use these Vector 3 data types in your  Roblox games again I hope this introduction to
  224. 24:37Vector 3 served you well continue to improve your  Roblox developer skills because sitting down and
  225. 24:42struggling through things that are tough for you  will make you a more competent Roblox developer
  226. 24:47in the long run and I believe you got this  so that's going to be for this episode join
  227. 24:51my Discord server the link is in the description  and I will see you in the next episode take care

About this transcript

This page contains the full transcript of Vector3 - Roblox Advanced Scripting #7 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,435 words across 227 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.