YouTube2Text

Drag Detectors (Draggable Objects) - Roblox Advanced Scripting #31 — Transcript

by BrawlDev · 7,525 words · 983 segments · language en · Watch on YouTube

Full transcript

  1. 0:00H I can't believe I took this job as a
  2. 0:02lumberjack I mean I have to pay the
  3. 0:04bills somehow and this seems to be the
  4. 0:05best way to go about it all right but I
  5. 0:07did find this pretty goodl looking tree
  6. 0:09here so I'm just going to take my Axe
  7. 0:10and see if we can make some wood out of
  8. 0:12this so if I just go up here and slash
  9. 0:15about then oh yeah all right we got a
  10. 0:16piece of wood damn this is a pretty big
  11. 0:18piece of wood too I hope I get paid big
  12. 0:20for this one all right so do I just take
  13. 0:23this and oh my god oh oh my God this
  14. 0:27wood is so heavy all right I better be
  15. 0:29getting paid big for this one all right
  16. 0:31I just need to move this to the Home
  17. 0:33Depot store so we can go ahead and sell
  18. 0:35this okay come on let's just move it to
  19. 0:38the store the store only a couple steps
  20. 0:41away okay this wood is so heavy as a
  21. 0:43matter of fact that it's literally
  22. 0:43Defying Gravity by floating around in
  23. 0:45place all right but if we just keep
  24. 0:47going then I think we should be pretty
  25. 0:48good let's just all right bring it to
  26. 0:49the store come on bring it in bring it
  27. 0:51in bring it in all right we're bringing
  28. 0:52it in pretty good oh oh yo it's just
  29. 0:56okay okay okay it's just flinging itself
  30. 0:58inside that's insan insane this is such
  31. 1:00a magical piece of wood let me tell you
  32. 1:02bro okay if we just bring this over here
  33. 1:05the cash register is right over there if
  34. 1:06we just move it move it move it move it
  35. 1:08move it over here okay all right we got
  36. 1:10the wood on the counter there we go all
  37. 1:13right Mr Lumberjack I want to take this
  38. 1:15piece of wood and I want to get some
  39. 1:16money out of it so what do you have to
  40. 1:18offer wait that log is too big I'm not
  41. 1:23taking that wait what do you mean this
  42. 1:25log is too big bro like if you want me
  43. 1:27to make it shorter I could just take my
  44. 1:29Axe and cut it for you you bro what what
  45. 1:32kind of Lumberjack doesn't take a log
  46. 1:34that's too big that makes no sense bro
  47. 1:36you are you are a very strange
  48. 1:39Lumberjack you know that if you don't
  49. 1:42get out of my story you'll become Timber
  50. 1:45yo what is the slander bro like okay I
  51. 1:48thought you were a very weird Lumberjack
  52. 1:50but you're also a very slanderous one
  53. 1:52too bro okay you know what I am not
  54. 1:54taking this mistreatment if you want to
  55. 1:57mistreat your Lumberjacks like that then
  56. 1:59then you are not looking at the right
  57. 2:00Lumberjack for the job I am sorry Mr
  58. 2:03Lumberjack okay and you know what as a
  59. 2:05matter of fact I'm just going to take my
  60. 2:06axe I'm just going to walk out of the
  61. 2:08store and pretend that I didn't even
  62. 2:09work here in the first place I think
  63. 2:11what best suited me is becoming a
  64. 2:13YouTuber rather than a lumberjack so I'm
  65. 2:15just going to walk out of here and
  66. 2:17pretend I've never seen you so I will
  67. 2:20never see you again Mr Lumberjack I'm
  68. 2:22going to walk out of here yo yo he
  69. 2:25actually took it for real bro he turned
  70. 2:28me into Lumber
  71. 2:31damn all right well I will take that as
  72. 2:33a lesson to never become a lumberjack
  73. 2:36ever again because I hate this
  74. 2:38job all right let's think about this for
  75. 2:40a minute in this episode we're going to
  76. 2:42be talking about drag detectors which is
  77. 2:44actually something I'm very much looking
  78. 2:45forward to talking about because a lot
  79. 2:48of the episodes in the advanced
  80. 2:49scripting tutorial guide up until this
  81. 2:51point have actually been using these
  82. 2:53drag detectors through these conceptual
  83. 2:55examples that I've been showing you
  84. 2:57throughout a lot of the episodes like I
  85. 2:59think this one is for the data storage
  86. 3:01video uh the one over here is for the
  87. 3:02Run service video and I believe the one
  88. 3:04over there is for the teleport service
  89. 3:06video so a drag detector basically
  90. 3:08allows you to take any 3D object and
  91. 3:11basically drag it around inside of the
  92. 3:13workspace so I take this part right here
  93. 3:16and then I can drag it in the game and
  94. 3:19it applies physics to be able to do some
  95. 3:22stupid stuff inside of the game like
  96. 3:23this now the purpose for this episode is
  97. 3:25to show you how to implement these how
  98. 3:27to configure these drag detectors so
  99. 3:29that they don't do stupid stuff like
  100. 3:31this where it can go into the void like
  101. 3:33it's no tomorrow and also Implement our
  102. 3:36own custom drag detectors if we have
  103. 3:37time for it in the end but that's going
  104. 3:39to be the goal for this episode and I'm
  105. 3:41going to be very much so looking forward
  106. 3:43to teaching this and I'm very excited
  107. 3:44for it so I hope you stick around all
  108. 3:46the way through till the end and with
  109. 3:47that being said let's now go ahead and
  110. 3:49go straight into implementing now that
  111. 3:51we understand it let's Implement drag
  112. 3:53detectors inside Roblox studio and the
  113. 3:55easiest way we can do that is just by
  114. 3:58simply adding a drag detector object and
  115. 4:00putting it inside of a 3D object in the
  116. 4:03workspace so here's what we're going to
  117. 4:05do I'm going to go to model and we're
  118. 4:07going to hit part just like this and on
  119. 4:10the right side in the Explorer we're
  120. 4:11going to hit the plus sign and we're
  121. 4:13going to search up a drag detector like
  122. 4:16this and now we have a drag detector
  123. 4:18object inside of this part right here so
  124. 4:21if we go into the game and hit play then
  125. 4:23we should be able to try this out for
  126. 4:24ourselves where we're able to drag this
  127. 4:27part inside of the workspace so if I
  128. 4:28hover over my map Mouse then we can see
  129. 4:30that it is draggable so if I hold down
  130. 4:33the left Mouse button and then drag it
  131. 4:34alongside the workspace it's using
  132. 4:37gravity to create this sort of motion
  133. 4:40that is trying to make the part go
  134. 4:43towards the direction that our Mouse is
  135. 4:45trying to go into and this is how we're
  136. 4:48able to create a very basic drag
  137. 4:50detector and make a part draggable but
  138. 4:52obviously with the default settings that
  139. 4:55this drag detector has um it can do a
  140. 4:58lot of stupid things and uh create
  141. 5:00results that we don't want so we need to
  142. 5:02be able to know how to configure drag
  143. 5:04detectors and how we can potentially
  144. 5:06create scripts to make these drag
  145. 5:08detectors useful and so that's what
  146. 5:09we're going to be doing inside of this
  147. 5:10episode the first feature I want to show
  148. 5:12with this drag detector is the way it
  149. 5:14responds to motion and basically what
  150. 5:16I'm referring to is how it uses physics
  151. 5:19or constraint forces to be able to drag
  152. 5:22this part to its desired location or
  153. 5:25orientation with wherever the mouse is
  154. 5:27located inside of the workspace while
  155. 5:29I'm dragging it so as you can see here
  156. 5:32it's using physics to be able to move
  157. 5:35this part to where it needs to go and
  158. 5:38this is what's called a response style
  159. 5:40and this response style is called
  160. 5:42physical because it's using in-game
  161. 5:45physics to be able to move this part to
  162. 5:47where it needs to be but there's
  163. 5:48actually another response style called
  164. 5:49geometric which I'm going to show you
  165. 5:51right about now so I'm just going to hit
  166. 5:52stop and if we go into our uh drag
  167. 5:55detector and we scroll down then there
  168. 5:57should be a property called response
  169. 5:59style and by default it's physical so
  170. 6:01this is what's using physics to be able
  171. 6:02to move the part to where it needs to go
  172. 6:05but if we hit this drop down there's two
  173. 6:06more options called custom and geometric
  174. 6:09and one thing to note about geometric is
  175. 6:11that it doesn't involve physics to try
  176. 6:14and get to the position that the drag
  177. 6:17detector is trying to make it go to if
  178. 6:19that makes sense so if I were to set
  179. 6:20this to geometric and if I were to show
  180. 6:23and if I were to show you this in game
  181. 6:24so by hitting play then if I drag this
  182. 6:27part then there's no physics in evolved
  183. 6:30when it comes to making the part go to
  184. 6:32where it needs to go it's kind of just
  185. 6:33it's happening simultaneously and that's
  186. 6:36kind of the difference between geometric
  187. 6:37and physical and I hope that this part
  188. 6:39has been making sense to you so far
  189. 6:41there's another quick thing to note
  190. 6:42about the drag detector's response style
  191. 6:45and that is determining if the object
  192. 6:47that this drag detector is part of is
  193. 6:50anchored or not and the reason this
  194. 6:52matters is because an anchored part by
  195. 6:54default does not get affected by physics
  196. 6:58or gravity so
  197. 7:00uh if there is any physical elements
  198. 7:02that are involved in this drag detector
  199. 7:03it's not going to work for an anchored
  200. 7:05part for that reason and I'm going to
  201. 7:06show you this so if we were to go back
  202. 7:09to physical response style and if I if I
  203. 7:12was to select the part that this drag
  204. 7:14detector is a part of and I select the
  205. 7:16anchored property and now I go to test
  206. 7:18and hit play Then This should basically
  207. 7:22uh be the same as a geometric response
  208. 7:25style in Disguise even though we said
  209. 7:27this should be a physical response Style
  210. 7:30so that's something I wanted to uh note
  211. 7:32here that if you're working with a
  212. 7:34response style you have to make sure
  213. 7:36that your part is either anchored or not
  214. 7:38anchored based on your specific needs
  215. 7:40for that and if I were to show you the
  216. 7:41other case scenarios here if let's say
  217. 7:44we had a geometric unanchored part so a
  218. 7:48geometric unanchored part will basically
  219. 7:50make the part unanchored by default but
  220. 7:52then once we're dragging the part it's
  221. 7:54actually going to Anchor the part while
  222. 7:56we're dragging it but then once we let
  223. 7:57go it's not going to be anchored any
  224. 7:59anymore so if I were to demonstrate this
  225. 8:00to you let's change the shape of this
  226. 8:02part to let's say a ball like this and
  227. 8:06I'm also going to make it a little bit
  228. 8:07bigger as well so if I hit play and if I
  229. 8:10were to roll this around then it's going
  230. 8:12to be unanchored but then if I use the
  231. 8:14drag detector it's going to Anchor the
  232. 8:16part but then once I let go it's going
  233. 8:18to go and roll off into the distance
  234. 8:20again because that's what happens when
  235. 8:22you use a geometric response time with
  236. 8:24an unanchored part but with an anchored
  237. 8:26part obviously it's not going to roll
  238. 8:28around at all and so that's something I
  239. 8:30wanted to add there for response style
  240. 8:31and I hope that this analogy or this
  241. 8:34explanation has helped you so far to
  242. 8:36understand it so now let's move on to
  243. 8:38the next part another important property
  244. 8:39we need to know here is the drag style
  245. 8:42and basically what this does is it
  246. 8:44determines how we want to drag this part
  247. 8:47that's inside of the game and there's a
  248. 8:49lot of options here to tell you what
  249. 8:52kind of style you want to have for your
  250. 8:53dragging and I'm going to go over some
  251. 8:55of the important ones here but let's try
  252. 8:56and break this down conceptually so if
  253. 8:58let's say I had this part and I wanted
  254. 9:00to move it alongside the X AIS which is
  255. 9:03in this direction or if I wanted to move
  256. 9:06it alongside the zais which is in this
  257. 9:08direction or if I wanted to drag it
  258. 9:10inside of the y direction which is uh up
  259. 9:12and down or if I even want to add a
  260. 9:15rotational element to this as well then
  261. 9:17we can do this by determining the drag
  262. 9:20style of where we want the part to be
  263. 9:24draggable towards basically so that's
  264. 9:27what we can do here with this drag style
  265. 9:29and and uh the first one I'm going to
  266. 9:30show you is called translate line and
  267. 9:33basically this drag style gives a
  268. 9:36one-dimensional motion alongside the
  269. 9:39drag detector's axis now I'm going to
  270. 9:42show you a little bit later how we can
  271. 9:43configure this direction in a little bit
  272. 9:46but by default the one-dimensional axis
  273. 9:49is in the y direction so if we were to
  274. 9:52use translate line then this is going to
  275. 9:54go up and down like this inside the Y
  276. 9:56AIS so if I were to just quickly change
  277. 9:59the response style back to physical and
  278. 10:01we need to make sure that our part is
  279. 10:02not anchored okay it's not anchored so
  280. 10:04if we now hit play then I'm going to
  281. 10:06show you what translate line looks like
  282. 10:08so it's going to only go up and down
  283. 10:11inside of the Y AIS because we specified
  284. 10:15translate line to be a one-dimensional
  285. 10:19motion alongside the drag detector's
  286. 10:21axis which is the y axis so now if we
  287. 10:24hit stop I'm going to show you the
  288. 10:26second drag style which if we go down
  289. 10:28here it's called transl plane which is
  290. 10:30basically a two-dimensional motion
  291. 10:33dragging style that goes along the axes
  292. 10:37that are perpendicular to the drag
  293. 10:40detector's axis so basically what I mean
  294. 10:42here is the drag detector's axis is in
  295. 10:45the y direction by default so that means
  296. 10:48the translate plane axes are going to be
  297. 10:51the ones that are going to be the
  298. 10:52opposite of the y- AIS so it's going to
  299. 10:55be in the x-axis and it's going to be in
  300. 10:57the z-axis not the Y one so if I were to
  301. 11:01go into the game I can show you this uh
  302. 11:03just by testing it so translate plane is
  303. 11:06going to allow me to drag it in the x-
  304. 11:07axis and it's also going to allow me to
  305. 11:09drag it in the z-axis just not in the y
  306. 11:12axis because that's what the axis for
  307. 11:16this drag uh detector currently is I
  308. 11:18hope this part is making sense so far
  309. 11:20once again I will show you how we can
  310. 11:21configure the drag Direction just a
  311. 11:23little bit but I hope so far this analog
  312. 11:25has been helping you understand these
  313. 11:28different uh drag styles
  314. 11:29so if I were to now hit stop and go to
  315. 11:31this drag detector there are some other
  316. 11:33ones that are pretty useful like rotate
  317. 11:35axis this is what allows you to have a
  318. 11:39rotational element to dragging your drag
  319. 11:42detector around just like this so it's
  320. 11:44not going to move but instead it's just
  321. 11:46going to rotate in place so I think
  322. 11:47that's another useful one and then one
  323. 11:49more that I'm going to show you is
  324. 11:51translate view plane which basically
  325. 11:54takes the part and it drags it alongside
  326. 11:58the player's screen so if I were to drag
  327. 12:00this alongside here then it's basically
  328. 12:02going to follow um where the view frame
  329. 12:06of the camera is inside of the game and
  330. 12:09so that is basically what translate view
  331. 12:11plane does so if I was uh let's say in
  332. 12:14first person then it's just going to
  333. 12:16drag alongside wherever the camera or
  334. 12:19the view frame is and so that is
  335. 12:21basically something that that would be
  336. 12:23pretty useful to have for this kind of
  337. 12:25drag style so those are some of the drag
  338. 12:27Styles I wanted to go over here but now
  339. 12:30but before I go over some of the other
  340. 12:32ones there is something else we need to
  341. 12:33know about first so there are other drag
  342. 12:35Styles here called translate line or
  343. 12:37plane or translate plane or line and you
  344. 12:40might be thinking what are these drag
  345. 12:42Styles well I can't exactly explain
  346. 12:44these drag Styles unless we understand
  347. 12:46another concept when it comes to drag
  348. 12:48detectors and that is called mode
  349. 12:51switching down here now basically what
  350. 12:53mode switching is is it allows the
  351. 12:55player to hold down a certain key to
  352. 12:59have this sort of modifier input to be
  353. 13:01able to change the drag style Midway
  354. 13:04while they're dragging a specific part
  355. 13:07so basically for PC we have to press the
  356. 13:10left control key to be able to switch
  357. 13:14our drag style Midway while we are
  358. 13:16dragging a certain part so with these
  359. 13:19certain drag Styles here with translate
  360. 13:21line or plane or translate plane or line
  361. 13:23if we were to let's say select translate
  362. 13:25plan or line basically what this is
  363. 13:27saying is for our
  364. 13:29primary drag style it's going to be
  365. 13:31translate plane that allows us to go on
  366. 13:34the x and z Direction but if we were to
  367. 13:37hold down this modifier input then it's
  368. 13:40going to switch the drag style to our
  369. 13:43secondary drag style which is translate
  370. 13:46line and that is basically what this is
  371. 13:48trying to say here so if I were to hit
  372. 13:50play I can show you what this looks like
  373. 13:51in game so our primary drag style is
  374. 13:55translate plane so it's going to go in
  375. 13:57the x and z Direction but if now let's
  376. 14:00say I held down the modifier input key
  377. 14:02which is left control like so and then I
  378. 14:05drag it then it's going to go up and
  379. 14:08down because it switched the drag style
  380. 14:10to go to our secondary drag style
  381. 14:12instead of our first one and then if I
  382. 14:14let go then it's just going to go back
  383. 14:15and switch to the primary drag style so
  384. 14:19that is uh something I wanted you to
  385. 14:20know about and it basically works the
  386. 14:22same way with translate liner plane it
  387. 14:24starts with translate line first but
  388. 14:27then once you press down the modifier
  389. 14:29input then it's going to switch to
  390. 14:30translate plane and I hope that this has
  391. 14:32made sense to you so for this next part
  392. 14:33we're going to change the physics of a
  393. 14:35drag detector and so before we do that
  394. 14:37what we're going to do is go to model
  395. 14:39and we're actually going to create a new
  396. 14:41part so let's hit the drop down here and
  397. 14:43let's insert a sphere like this and what
  398. 14:46we're also going to do is create a new
  399. 14:48drag detector and put it inside of this
  400. 14:49part so I'm going to hit the plus sign
  401. 14:51and I'm going to insert a drag detector
  402. 14:53just like this and so basically what
  403. 14:55we're going to change here is if we
  404. 14:57scroll down here the phys physics
  405. 14:59response category with all these
  406. 15:01properties that are associated with it
  407. 15:03and so if you remember what I mentioned
  408. 15:05earlier in this episode The response
  409. 15:07Style with physical is basically what
  410. 15:10allows physics to be incorporated with
  411. 15:12the dragging of this drag style and so
  412. 15:15it's determined through these properties
  413. 15:17down here with apply at Center of mass
  414. 15:20Max Force Max torque and responsiveness
  415. 15:22now you might be confused with what all
  416. 15:24these properties mean so I'm going to
  417. 15:25try and explain each one of them to the
  418. 15:26best of my knowledge but basically Max
  419. 15:28Force
  420. 15:29determines how much force we want to
  421. 15:32apply to this part to be able to reach
  422. 15:35its goal and this is the maximum that
  423. 15:37we're going to give it so if it's
  424. 15:39anything that's after this number then
  425. 15:42it's basically going to be too fast and
  426. 15:43we don't want it to exceed the max force
  427. 15:46but this is actually a very very large
  428. 15:48number and that's actually the reason
  429. 15:50why it can go off into the void so
  430. 15:52easily because of it so what we can do
  431. 15:54is actually decrease this Max Force from
  432. 15:5610 million to let's say uh 10,000
  433. 16:00instead and so if we go hit test and hit
  434. 16:02play then what we should see is if we
  435. 16:05drag this part around then it's not
  436. 16:07going to go off into the void as it was
  437. 16:10able to before it it's kind of taking
  438. 16:12its time just a little bit but if we
  439. 16:14want to really see the change then we
  440. 16:16can actually decrease this even further
  441. 16:18to let's say 1,000 then it's going to
  442. 16:21make it even slower because we're uh not
  443. 16:24going to be applying a super big Max
  444. 16:27Force to be able to reach the goal that
  445. 16:29we're trying to make it reach towards so
  446. 16:31that is what Max Force basically does it
  447. 16:33limits how much force we can apply at
  448. 16:37any given time for it to reach its goal
  449. 16:39and that's basically what it is so the
  450. 16:40next property is Max torque which is
  451. 16:43basically the rotational counterpart to
  452. 16:46Max Force so max force deals with how
  453. 16:49much force is either being pushed or
  454. 16:50pulled but this basically determines the
  455. 16:52rotational aspect of it which is how
  456. 16:55fast or how slow a part gets rotated
  457. 16:57around like so and torque is basically
  458. 17:00how much of it do we want to maximize
  459. 17:02before it reaches a certain point where
  460. 17:03we don't want it to go even faster than
  461. 17:05it than it should so that is basically
  462. 17:08what Max torque is and responsiveness is
  463. 17:10how fast do we want this part to respond
  464. 17:13to this new location that we're trying
  465. 17:15to make it go to so a good way to think
  466. 17:18about this is the higher the number of
  467. 17:19responsiveness the more responsive it is
  468. 17:22you know like how it's like quicker to
  469. 17:25reach the goal that it needs to reach
  470. 17:27towards so if we were to make the Max
  471. 17:29Force let's say uh 10,000 and we were to
  472. 17:32change the responsiveness to 100 so it's
  473. 17:35it's rapidly more responsive than it was
  474. 17:37before then it's going to reach the goal
  475. 17:40a lot faster as you can see here it's
  476. 17:42it's basically almost instantaneously
  477. 17:45going to uh the direction or location of
  478. 17:47where my mouse is going and that's
  479. 17:48basically what responsiveness does it's
  480. 17:51how fast do we want this part to be able
  481. 17:54to reach its goal without having to
  482. 17:57exceed the max torque or max force that
  483. 18:00we specified this part to be and I hope
  484. 18:02that some of these properties have been
  485. 18:03making sense to you and it honestly just
  486. 18:05comes down to experimentation to see
  487. 18:07which one works best for you but this is
  488. 18:10a little small introduction to some of
  489. 18:11the properties but there is one more
  490. 18:13property here called apply at Center of
  491. 18:16mass and basically what this does is do
  492. 18:18we want to have the force or the the
  493. 18:21focal point of the uh of the physics be
  494. 18:24involved with the center of the part
  495. 18:27that we're trying to change or is it
  496. 18:29going to be where our Mouse is located
  497. 18:31when we're dragging it so if I were to
  498. 18:33set this property to be true and if I
  499. 18:35were to go into the game then I can show
  500. 18:36you what this looks like visually so if
  501. 18:39I were to let's say hold the part on the
  502. 18:41left side here then it's going to move
  503. 18:42the part to the center of where my mouse
  504. 18:46is located so if I let go and then try
  505. 18:48this again on the right side then it's
  506. 18:49going to move the the center of Mass to
  507. 18:52where my mouse is located now if I were
  508. 18:55to disable apply at Center of mass again
  509. 18:58then it's going to make the uh Center of
  510. 19:01mass be wherever my mouse is currently
  511. 19:04now there's one thing you may or may not
  512. 19:06have noticed but if we let's say change
  513. 19:08the response style to geometric then the
  514. 19:11category for physical response is gone
  515. 19:13obviously because if we're working with
  516. 19:15the geometric response style then we're
  517. 19:17not applying physics to this part so
  518. 19:19that's why this category will only show
  519. 19:22if we have a response style of physical
  520. 19:24so that's one thing I wanted to add
  521. 19:26before uh we move on to the next part of
  522. 19:28this episode and I hope that you found
  523. 19:29these properties to be useful so I
  524. 19:31mentioned earlier in this episode we can
  525. 19:32change the drag direction of a drag
  526. 19:35detector for a part and basically what
  527. 19:37I'm referring to is by default if we
  528. 19:39remember the axis so if we go down here
  529. 19:42inside the drag directions category
  530. 19:44there's this property called axis and by
  531. 19:47default the axis for this drag detector
  532. 19:50is in the Y AIS so when we started with
  533. 19:53translate line as our drag style it's
  534. 19:56giving us a one-dimensional motion
  535. 19:59along the axis of this drag detector
  536. 20:02which is in the y direction but we can
  537. 20:04actually change this drag direction to
  538. 20:06be something that's not in the Y AIS but
  539. 20:08instead let's say in the xaxis or the
  540. 20:11z-axis so if I were to change the y-
  541. 20:14axis to zero and if I were to change the
  542. 20:18uh let's say x AIS to one so if we hit
  543. 20:21enter just like this then what we should
  544. 20:23see is if we go into the game and hit
  545. 20:26play then we should be able to drag our
  546. 20:29part alongside the x axis for our
  547. 20:32translate line dragging style since it
  548. 20:34gives us a one-dimensional motion
  549. 20:36alongside the axis but it's no longer a
  550. 20:38part of the Y AIS Dimension because we
  551. 20:41changed it so we can do the same thing
  552. 20:43with let's say Z so if we were to change
  553. 20:46X back to zero and then we were to
  554. 20:47change Z to one then we're going to hit
  555. 20:49play and then it's only going to go
  556. 20:51alongside the Z AIS just like this and
  557. 20:54nowhere else and we can do some pretty
  558. 20:56interesting stuff here with let's say if
  559. 20:57we were to change the the drag style to
  560. 20:59translate line or plane if you remember
  561. 21:02with translate plane it's the two axes
  562. 21:05that are perpendicular to the axis so in
  563. 21:09this case our axis is now Z so if
  564. 21:12whatever so the axes that are
  565. 21:13perpendicular to it are X and Y for
  566. 21:16translate plane so if we were to go and
  567. 21:18hit play then it's going to start in the
  568. 21:21Z axis for translate line but then if we
  569. 21:23hold down our input modifier which is
  570. 21:25left control then it's going to switch
  571. 21:27to translate which is the y direction
  572. 21:31and also the X Direction so it's going
  573. 21:33to go something like this and it
  574. 21:35honestly requires a bunch of uh
  575. 21:37experimentation to try and figure out
  576. 21:39what works best for you when it comes to
  577. 21:42changing the drag Direction and I want
  578. 21:44you to keep note of this if you do
  579. 21:46decide to change the drag direction of a
  580. 21:48drag detector it depends on what your
  581. 21:50needs are so this honestly requires some
  582. 21:52experimentation but I hope that you
  583. 21:54found this part to be pretty informative
  584. 21:55so far now there's another thing you may
  585. 21:57have noticed and that is when whenever
  586. 21:58we're changing our axis it's also
  587. 22:00changing a bunch of these properties
  588. 22:02down here but I think an important one
  589. 22:04to know is the orientation here so this
  590. 22:07is another Vector 3 value which gives us
  591. 22:09an X Y and Z value that basically
  592. 22:11determines if we were to have a
  593. 22:13rotational drag style so if you were to
  594. 22:15change this to rotate axis this is the
  595. 22:18direction that this part is going to go
  596. 22:21if we decide to rotate it and the way we
  597. 22:23can really see this is if we were to
  598. 22:25change the response style to geometric
  599. 22:27because if we were to use physical then
  600. 22:29we won't be able to see the changes
  601. 22:30properly because it's being affected by
  602. 22:32uh the physical constraints so if we
  603. 22:34were to drag this then it's going to
  604. 22:36drag like this which we specified the
  605. 22:39orientation to be but if we were to
  606. 22:41change the axis to Y so if I were to
  607. 22:43make z0 and then y to 1 then it's going
  608. 22:47to change the orientation again and this
  609. 22:48is going to have a different rotational
  610. 22:51Direction uh for this part just like
  611. 22:54this and so Roblox will automatically
  612. 22:56configure the orientation or the axis if
  613. 23:00you change either one of those two and
  614. 23:01that's another thing I want you to
  615. 23:02consider when it comes to those sorts of
  616. 23:05things and so I hope you found this part
  617. 23:06to be helpful for this next part I'm
  618. 23:07going to be introducing movement limits
  619. 23:10which basically allows us to have a
  620. 23:12certain limit of how far we can drag
  621. 23:15something out before it reaches a
  622. 23:17certain point so I created this little
  623. 23:19drawer example here where we basically
  624. 23:21drag this middle part outward like this
  625. 23:24and then once we reach a certain point
  626. 23:27then it's not going to be able to be
  627. 23:29draggable past this certain point right
  628. 23:31here but instead we could just drag it
  629. 23:33back inside like this and it can't go
  630. 23:35outside this way as well so this is the
  631. 23:38only space that we can allow movement to
  632. 23:41happen with this drag detector and so
  633. 23:43we're essentially going to be recreating
  634. 23:44this drawer system right here so I'm now
  635. 23:46going to hit stop so we can go ahead and
  636. 23:48recreate the system all right so what
  637. 23:49I'm going to do is go to model we're
  638. 23:51going to go down to part and we're going
  639. 23:53to insert a block like this and I'm just
  640. 23:56going to scale the part just like this
  641. 24:00and I'm also going to change the color
  642. 24:04to let's say this reddish brown color
  643. 24:07and what I'm also going to do is
  644. 24:09duplicate this part to make it go up
  645. 24:11like this and I'm also going to
  646. 24:12duplicate it one more time just like
  647. 24:14this and I'm I'm actually going to take
  648. 24:16all these parts and I'm going to right
  649. 24:18click and I'm going to group as a model
  650. 24:21like this and I'm just going to call
  651. 24:23this drawer like that and so now what
  652. 24:26we're going to do is if we open up this
  653. 24:28there is going to be the middle part
  654. 24:29which should be this one right here so
  655. 24:32I'm going to call this one drawer and
  656. 24:35I'm also going to change the color of
  657. 24:38this drawer to let's say black just to
  658. 24:40differentiate it and what I'm also going
  659. 24:42to do is specify this top right here as
  660. 24:45well and this is going to be important
  661. 24:47later and I'll show you why so what
  662. 24:49we're going to do for the drawer is hit
  663. 24:50the plus sign we're going to insert a
  664. 24:52drag detector like this and there's
  665. 24:55going to be a few important things we
  666. 24:57need to do first so one thing is for our
  667. 25:00parts that are not the drawer we're
  668. 25:02going to go down and we're going to
  669. 25:04Anchor them because we're not going to
  670. 25:05make them dragable and then for this
  671. 25:07drawer what we're going to do is for
  672. 25:10this drag detector we're going to make
  673. 25:12the response style geometric and we're
  674. 25:15also going to make the drag style
  675. 25:17translate line because we only want it
  676. 25:19to go in One Direction here so that is
  677. 25:23basically what we have going on so far
  678. 25:26and what we also need to do is change
  679. 25:28the axis of the drag Direction because
  680. 25:31by default it's in the y direction so if
  681. 25:33we left it as is then it's only going to
  682. 25:35be able to go up and down but we want it
  683. 25:37to go in the X Direction like this so we
  684. 25:40are going to essentially go to the drag
  685. 25:42detector we're going to change the axis
  686. 25:46to have one as the x axis and then zero
  687. 25:49as the y axis just like this and so
  688. 25:53basically that is essentially what we
  689. 25:54have going on so far so if we hit play
  690. 25:56here then we should basically be able to
  691. 26:00drag this alongside the X Direction but
  692. 26:02you may have noticed there is no limit
  693. 26:04to how far we can drag this thing and
  694. 26:07this is basically where dragging
  695. 26:09limitations come in and that's what
  696. 26:10we're going to be adding here so if we
  697. 26:12hit stop then there's this section here
  698. 26:14called drag limits and there's two
  699. 26:16properties that's going to be important
  700. 26:17for us here the first one is Max drag
  701. 26:21translation and then this one is min
  702. 26:23drag translation so with Min and Max
  703. 26:25basically with these coordinates how far
  704. 26:27do we want to be able to drag this part
  705. 26:30in a certain direction which is the max
  706. 26:32and minimum is how far do we want to be
  707. 26:34able to drag this in the opposite
  708. 26:36direction now here's one thing you have
  709. 26:38to be very careful about here so if
  710. 26:40we're going in the X Direction it goes
  711. 26:44incrementally this way so it's going to
  712. 26:47increase the number ever so slightly if
  713. 26:49you notice the positional value on the
  714. 26:51right side here it's increasing in this
  715. 26:53direction but what we want is for this
  716. 26:57to go in the opposite direction here as
  717. 27:00you can see the position is going
  718. 27:02further down the list so instead of
  719. 27:04using Max drag translation we're
  720. 27:06actually going to use Min drag
  721. 27:08translation because this is how far we
  722. 27:12can go in the opposite direction I hope
  723. 27:14that that part is making sense so
  724. 27:16basically what we're going to do here is
  725. 27:17for the Min drag translation we're going
  726. 27:19to set this to five in the X Direction
  727. 27:21and we're not even going to change
  728. 27:23anything in the Max uh drag translation
  729. 27:25because we're not concerned about what's
  730. 27:27happening over over here in this
  731. 27:29direction but instead if we have the max
  732. 27:31translation to zero then we can't go
  733. 27:34anywhere past this point here so if we
  734. 27:37now hit play Then basically what we
  735. 27:39should see is that we can drag uh oh
  736. 27:44hold on hold on I messed something up
  737. 27:46here okay okay so there's a little typo
  738. 27:49here this should be -5 for the minimum
  739. 27:52translation and not five because we're
  740. 27:55going to be going in the opposite
  741. 27:56direction and that's what's going to
  742. 27:58be changed with the X direction is that
  743. 28:00it's going to go down further this way
  744. 28:02so if we now drag it all the way back
  745. 28:04here then there should be a limit to how
  746. 28:07far we can go back and obviously the
  747. 28:09constraint for going on the right side
  748. 28:11is nothing it's just going to be at zero
  749. 28:13so this is all we can do for this
  750. 28:16dragging which is exactly what we want
  751. 28:18but unfortunately we're not done here
  752. 28:21and I will show you why so there's
  753. 28:23something in the documentation where
  754. 28:25they mention how dragging limits is not
  755. 28:28not the same thing as constraints so
  756. 28:30basically what I'm referring to here is
  757. 28:32if we drag this this is how far we can
  758. 28:35drag this part within a specific drag
  759. 28:38but if I let go and then I drag it again
  760. 28:41then oh you see you see what happened
  761. 28:44there it's now dragging past where it
  762. 28:46needs to go because once my drag is done
  763. 28:50then it basically resets the maximum or
  764. 28:53minimum uh limit that I had with this
  765. 28:55drag detector so when you're in a
  766. 28:57situation like this how would you
  767. 28:59exactly fix this well there is most
  768. 29:01certainly one way we can fix this and
  769. 29:03this is with the use of a reference
  770. 29:05instance so I'm going to show you what
  771. 29:07this is uh right now so in order to fix
  772. 29:09a problem like this we need to have
  773. 29:10what's called a reference instance which
  774. 29:13is basically an instance that this drag
  775. 29:15detector is applied to that gives the
  776. 29:19reference frame that we are going to use
  777. 29:22to determine if our drag has exceeded
  778. 29:26this reference position or frame or
  779. 29:28whatever it is that we're trying to use
  780. 29:30here and the reason this is important is
  781. 29:32because let's say we were to drag this
  782. 29:33part alongside here then the reference
  783. 29:36is still inside of the middle of this
  784. 29:39part that's right over here with this
  785. 29:40drag detector so the only reference that
  786. 29:42it has is the center of this part so
  787. 29:45because the reference is here we can go5
  788. 29:48studs back down this way but the
  789. 29:51position keeps changing so what we need
  790. 29:54is a reference that stays in place with
  791. 29:57this drawer dra so that it actually
  792. 30:00doesn't exceed that position and so I
  793. 30:02hope once you understand it this way
  794. 30:04then you can probably see the importance
  795. 30:06of having a reference instance for this
  796. 30:08but you might ask what kind of reference
  797. 30:10instance are we going to have for this
  798. 30:11drag detector well we can most certainly
  799. 30:14use something that pertains to this
  800. 30:16drawer like this top part that I said
  801. 30:19was going to be important later because
  802. 30:21this gives us a reference frame for
  803. 30:24where the drawer is located so basically
  804. 30:26the way we're able to do this is if we
  805. 30:28take the drag detector there's this
  806. 30:30property called reference instance so if
  807. 30:31we select this then we can select the
  808. 30:33instance that we want this reference to
  809. 30:35be a part of so what I'm going to do is
  810. 30:37select the top part here so now once
  811. 30:40we're able to do this then this
  812. 30:42basically gives us a reference point of
  813. 30:45where we want this part to be able to
  814. 30:48move uh far away from but not too far
  815. 30:50away from this reference point so that
  816. 30:52is the only thing we need to do here so
  817. 30:54now if we hit play then what we should
  818. 30:56see is if we drag this part alongside
  819. 30:58here then we can't drag this further
  820. 31:01along because it's not going to go past
  821. 31:05the reference frame point of this top
  822. 31:07part here it's not going to go past it
  823. 31:09and also I noticed that this is
  824. 31:10glitching out a little bit and that's
  825. 31:11probably because it's a good practice to
  826. 31:13make these parts anchored when you're
  827. 31:15doing a reference style here so that is
  828. 31:16basically how we create a drawer system
  829. 31:18using these drag detectors now if I were
  830. 31:21to rotate this part alongside this
  831. 31:23direction then it's not going to affect
  832. 31:26the axis whatsoever and we're still able
  833. 31:28to make a drawer system work just like
  834. 31:31this and I hope from my explanation and
  835. 31:33also from everything we've learned up
  836. 31:35until this point that uh you were able
  837. 31:37to get a good understanding of how these
  838. 31:38drag detectors work now there are
  839. 31:40scripting events we can use to detect
  840. 31:43certain things like did the player start
  841. 31:45dragging this part or is the player
  842. 31:48still dragging this part or did they
  843. 31:50stop dragging this part uh we can do
  844. 31:51that there a script so what I'm going to
  845. 31:53do is go to the drawer and we're going
  846. 31:54to hit the plus sign and we're going to
  847. 31:56insert a script like this so so I'm
  848. 31:58going to make reference to the drag
  849. 32:00Detector by saying local drag detector
  850. 32:04equals script. par. drag detector like
  851. 32:06this and what I'm going to do here is
  852. 32:08say drag detector.
  853. 32:11dragstart colon connect function open
  854. 32:14close parentheses enter and there are a
  855. 32:16lot of parameters that does get past
  856. 32:19here but the one that we're going to be
  857. 32:20focused on is the player who did drag
  858. 32:22this part so we're going to pass in the
  859. 32:24player and we can just print something
  860. 32:26like player. name concatenate with has
  861. 32:30started dragging like this and then
  862. 32:33there's other events like drag detector.
  863. 32:36drag continue colon connect function
  864. 32:39pass in the player like this and we
  865. 32:41could just take this print statement and
  866. 32:43paste it down here is still dragging
  867. 32:47like this and then finally there's
  868. 32:49another one called drag detector.
  869. 32:51dragend colon connect function open
  870. 32:54close parentheses
  871. 32:56player enter and then we can basically
  872. 33:00copy this paste down here has ended or
  873. 33:03has stopped dragging like this so drag
  874. 33:07start it only fires once once the player
  875. 33:09actually does start dragging this drag
  876. 33:11detector drag continue is going to
  877. 33:14repeatedly print this statement out for
  878. 33:16every frame that the drag is being
  879. 33:19dragged across the screen and the drag
  880. 33:21end is only going to fire once once we
  881. 33:23let go of the drag so if we were to test
  882. 33:26this out in game then we can hold uh the
  883. 33:30drag and then it's going to print in the
  884. 33:31output saying brawl battle has started
  885. 33:33dragging and then once we drag it's
  886. 33:35going to continuously print the
  887. 33:37statement for every time that the frame
  888. 33:41for this dragging changes and then once
  889. 33:42I let go then it's going to say brawl
  890. 33:44battle has stopped dragging and there's
  891. 33:46other ways we can get information about
  892. 33:49this drag using a property and this
  893. 33:52property is called drag frame down here
  894. 33:54which basically consists of two values a
  895. 33:56positional value and an orientation
  896. 33:58value and this tells us what position
  897. 34:01this drag is currently taking place in
  898. 34:04and then once we let go of the drag
  899. 34:05that's when it resets back to zero for
  900. 34:08both position and orientation so we can
  901. 34:10do that down here by detecting it by
  902. 34:12saying drag detector colon get property
  903. 34:16changed signal open and close
  904. 34:18parentheses and then whatever the
  905. 34:19property is here which is drag frame and
  906. 34:22then we're going to connect this to a
  907. 34:24function so connect function open close
  908. 34:27parentheses please enter and we can
  909. 34:29basically get any information we want
  910. 34:31from this drag frame so we can let's say
  911. 34:33print out the drag detector. drag
  912. 34:38frame. position just like this and this
  913. 34:41is something we can print out obviously
  914. 34:43there's other things we can print here
  915. 34:44like the orientation or there's even
  916. 34:46more specific things we can do so drag
  917. 34:49frame. position do uh magnitude unit and
  918. 34:52if we don't want the position then we
  919. 34:53can have something different like the
  920. 34:54look vector and all these other sorts of
  921. 34:56vectors here but but let's say we want
  922. 34:58to locate the position so I'm going to
  923. 35:01comment out this drag continue event
  924. 35:03here and now we're going to hit play so
  925. 35:05we should be able to see what happens to
  926. 35:07the position of the drag whenever we're
  927. 35:09moving alongside the X Direction it's
  928. 35:12slowly yet surely decreasing the X
  929. 35:17position of this part right here and so
  930. 35:20that is something I want you to take
  931. 35:21away from this and as you can see the
  932. 35:23limit came down to when it reached ne5
  933. 35:26and we can't go down any further past
  934. 35:27this point and then if we make it go
  935. 35:28back down this way then it's going to
  936. 35:30reset back down to zero and that is
  937. 35:32essentially some pretty useful things we
  938. 35:34can use when it comes to scripting these
  939. 35:36drag detectors and I hope you found this
  940. 35:37part to be helpful so that is basically
  941. 35:40the introduction to drag detectors now
  942. 35:42there are some things I did not get to
  943. 35:43cover in this episode like permission
  944. 35:46policy which is basically which player
  945. 35:48can drag this part or if anybody can
  946. 35:51drag this part as a matter of fact and
  947. 35:52then there's other ones like whether we
  948. 35:55can run this locally on the player side
  949. 35:57so so that no other player can see the
  950. 35:59dragging that's happening I will let you
  951. 36:00experiment and try these things out for
  952. 36:03yourself but I think for the most part I
  953. 36:05was able to at least get you to try
  954. 36:08these drag detectors out for yourself
  955. 36:10and I hope that you found this video to
  956. 36:11be very very informative and I
  957. 36:13definitely enjoyed making this episode
  958. 36:14now before you go I want to give a shout
  959. 36:16out to my second and third patreon
  960. 36:18members boopy your noose and tri vjf but
  961. 36:22he likes to go by T for short for
  962. 36:24directly supporting me through my
  963. 36:25patreon and it's h honly just it's very
  964. 36:28heartwarming to see that there are
  965. 36:30people where I've impacted them so much
  966. 36:32through my videos that they'd be willing
  967. 36:34to support me through my patreon and
  968. 36:36that is something I I really love to see
  969. 36:38and I and I can't be more grateful that
  970. 36:40I have people who are like that um but
  971. 36:43anyways if you want to do the same thing
  972. 36:44for me I will leave a link to my patreon
  973. 36:46page in the description where you can
  974. 36:48get access to all of my scripts and
  975. 36:51assets that I've created throughout this
  976. 36:53entire series and you can also get
  977. 36:55access to videos early for everyone else
  978. 36:58and maybe some additional bonus content
  979. 37:01that I will occasionally put out on on
  980. 37:02my patreon as well so go ahead and check
  981. 37:04that out and with that I will now
  982. 37:06conclude this episode I will see you in
  983. 37:08the next one take care

About this transcript

This page contains the full transcript of Drag Detectors (Draggable Objects) - Roblox Advanced Scripting #31 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 7,525 words across 983 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.