Drag Detectors (Draggable Objects) - Roblox Advanced Scripting #31 — Transcript
Full transcript
- 0:00H I can't believe I took this job as a
- 0:02lumberjack I mean I have to pay the
- 0:04bills somehow and this seems to be the
- 0:05best way to go about it all right but I
- 0:07did find this pretty goodl looking tree
- 0:09here so I'm just going to take my Axe
- 0:10and see if we can make some wood out of
- 0:12this so if I just go up here and slash
- 0:15about then oh yeah all right we got a
- 0:16piece of wood damn this is a pretty big
- 0:18piece of wood too I hope I get paid big
- 0:20for this one all right so do I just take
- 0:23this and oh my god oh oh my God this
- 0:27wood is so heavy all right I better be
- 0:29getting paid big for this one all right
- 0:31I just need to move this to the Home
- 0:33Depot store so we can go ahead and sell
- 0:35this okay come on let's just move it to
- 0:38the store the store only a couple steps
- 0:41away okay this wood is so heavy as a
- 0:43matter of fact that it's literally
- 0:43Defying Gravity by floating around in
- 0:45place all right but if we just keep
- 0:47going then I think we should be pretty
- 0:48good let's just all right bring it to
- 0:49the store come on bring it in bring it
- 0:51in bring it in all right we're bringing
- 0:52it in pretty good oh oh yo it's just
- 0:56okay okay okay it's just flinging itself
- 0:58inside that's insan insane this is such
- 1:00a magical piece of wood let me tell you
- 1:02bro okay if we just bring this over here
- 1:05the cash register is right over there if
- 1:06we just move it move it move it move it
- 1:08move it over here okay all right we got
- 1:10the wood on the counter there we go all
- 1:13right Mr Lumberjack I want to take this
- 1:15piece of wood and I want to get some
- 1:16money out of it so what do you have to
- 1:18offer wait that log is too big I'm not
- 1:23taking that wait what do you mean this
- 1:25log is too big bro like if you want me
- 1:27to make it shorter I could just take my
- 1:29Axe and cut it for you you bro what what
- 1:32kind of Lumberjack doesn't take a log
- 1:34that's too big that makes no sense bro
- 1:36you are you are a very strange
- 1:39Lumberjack you know that if you don't
- 1:42get out of my story you'll become Timber
- 1:45yo what is the slander bro like okay I
- 1:48thought you were a very weird Lumberjack
- 1:50but you're also a very slanderous one
- 1:52too bro okay you know what I am not
- 1:54taking this mistreatment if you want to
- 1:57mistreat your Lumberjacks like that then
- 1:59then you are not looking at the right
- 2:00Lumberjack for the job I am sorry Mr
- 2:03Lumberjack okay and you know what as a
- 2:05matter of fact I'm just going to take my
- 2:06axe I'm just going to walk out of the
- 2:08store and pretend that I didn't even
- 2:09work here in the first place I think
- 2:11what best suited me is becoming a
- 2:13YouTuber rather than a lumberjack so I'm
- 2:15just going to walk out of here and
- 2:17pretend I've never seen you so I will
- 2:20never see you again Mr Lumberjack I'm
- 2:22going to walk out of here yo yo he
- 2:25actually took it for real bro he turned
- 2:28me into Lumber
- 2:31damn all right well I will take that as
- 2:33a lesson to never become a lumberjack
- 2:36ever again because I hate this
- 2:38job all right let's think about this for
- 2:40a minute in this episode we're going to
- 2:42be talking about drag detectors which is
- 2:44actually something I'm very much looking
- 2:45forward to talking about because a lot
- 2:48of the episodes in the advanced
- 2:49scripting tutorial guide up until this
- 2:51point have actually been using these
- 2:53drag detectors through these conceptual
- 2:55examples that I've been showing you
- 2:57throughout a lot of the episodes like I
- 2:59think this one is for the data storage
- 3:01video uh the one over here is for the
- 3:02Run service video and I believe the one
- 3:04over there is for the teleport service
- 3:06video so a drag detector basically
- 3:08allows you to take any 3D object and
- 3:11basically drag it around inside of the
- 3:13workspace so I take this part right here
- 3:16and then I can drag it in the game and
- 3:19it applies physics to be able to do some
- 3:22stupid stuff inside of the game like
- 3:23this now the purpose for this episode is
- 3:25to show you how to implement these how
- 3:27to configure these drag detectors so
- 3:29that they don't do stupid stuff like
- 3:31this where it can go into the void like
- 3:33it's no tomorrow and also Implement our
- 3:36own custom drag detectors if we have
- 3:37time for it in the end but that's going
- 3:39to be the goal for this episode and I'm
- 3:41going to be very much so looking forward
- 3:43to teaching this and I'm very excited
- 3:44for it so I hope you stick around all
- 3:46the way through till the end and with
- 3:47that being said let's now go ahead and
- 3:49go straight into implementing now that
- 3:51we understand it let's Implement drag
- 3:53detectors inside Roblox studio and the
- 3:55easiest way we can do that is just by
- 3:58simply adding a drag detector object and
- 4:00putting it inside of a 3D object in the
- 4:03workspace so here's what we're going to
- 4:05do I'm going to go to model and we're
- 4:07going to hit part just like this and on
- 4:10the right side in the Explorer we're
- 4:11going to hit the plus sign and we're
- 4:13going to search up a drag detector like
- 4:16this and now we have a drag detector
- 4:18object inside of this part right here so
- 4:21if we go into the game and hit play then
- 4:23we should be able to try this out for
- 4:24ourselves where we're able to drag this
- 4:27part inside of the workspace so if I
- 4:28hover over my map Mouse then we can see
- 4:30that it is draggable so if I hold down
- 4:33the left Mouse button and then drag it
- 4:34alongside the workspace it's using
- 4:37gravity to create this sort of motion
- 4:40that is trying to make the part go
- 4:43towards the direction that our Mouse is
- 4:45trying to go into and this is how we're
- 4:48able to create a very basic drag
- 4:50detector and make a part draggable but
- 4:52obviously with the default settings that
- 4:55this drag detector has um it can do a
- 4:58lot of stupid things and uh create
- 5:00results that we don't want so we need to
- 5:02be able to know how to configure drag
- 5:04detectors and how we can potentially
- 5:06create scripts to make these drag
- 5:08detectors useful and so that's what
- 5:09we're going to be doing inside of this
- 5:10episode the first feature I want to show
- 5:12with this drag detector is the way it
- 5:14responds to motion and basically what
- 5:16I'm referring to is how it uses physics
- 5:19or constraint forces to be able to drag
- 5:22this part to its desired location or
- 5:25orientation with wherever the mouse is
- 5:27located inside of the workspace while
- 5:29I'm dragging it so as you can see here
- 5:32it's using physics to be able to move
- 5:35this part to where it needs to go and
- 5:38this is what's called a response style
- 5:40and this response style is called
- 5:42physical because it's using in-game
- 5:45physics to be able to move this part to
- 5:47where it needs to be but there's
- 5:48actually another response style called
- 5:49geometric which I'm going to show you
- 5:51right about now so I'm just going to hit
- 5:52stop and if we go into our uh drag
- 5:55detector and we scroll down then there
- 5:57should be a property called response
- 5:59style and by default it's physical so
- 6:01this is what's using physics to be able
- 6:02to move the part to where it needs to go
- 6:05but if we hit this drop down there's two
- 6:06more options called custom and geometric
- 6:09and one thing to note about geometric is
- 6:11that it doesn't involve physics to try
- 6:14and get to the position that the drag
- 6:17detector is trying to make it go to if
- 6:19that makes sense so if I were to set
- 6:20this to geometric and if I were to show
- 6:23and if I were to show you this in game
- 6:24so by hitting play then if I drag this
- 6:27part then there's no physics in evolved
- 6:30when it comes to making the part go to
- 6:32where it needs to go it's kind of just
- 6:33it's happening simultaneously and that's
- 6:36kind of the difference between geometric
- 6:37and physical and I hope that this part
- 6:39has been making sense to you so far
- 6:41there's another quick thing to note
- 6:42about the drag detector's response style
- 6:45and that is determining if the object
- 6:47that this drag detector is part of is
- 6:50anchored or not and the reason this
- 6:52matters is because an anchored part by
- 6:54default does not get affected by physics
- 6:58or gravity so
- 7:00uh if there is any physical elements
- 7:02that are involved in this drag detector
- 7:03it's not going to work for an anchored
- 7:05part for that reason and I'm going to
- 7:06show you this so if we were to go back
- 7:09to physical response style and if I if I
- 7:12was to select the part that this drag
- 7:14detector is a part of and I select the
- 7:16anchored property and now I go to test
- 7:18and hit play Then This should basically
- 7:22uh be the same as a geometric response
- 7:25style in Disguise even though we said
- 7:27this should be a physical response Style
- 7:30so that's something I wanted to uh note
- 7:32here that if you're working with a
- 7:34response style you have to make sure
- 7:36that your part is either anchored or not
- 7:38anchored based on your specific needs
- 7:40for that and if I were to show you the
- 7:41other case scenarios here if let's say
- 7:44we had a geometric unanchored part so a
- 7:48geometric unanchored part will basically
- 7:50make the part unanchored by default but
- 7:52then once we're dragging the part it's
- 7:54actually going to Anchor the part while
- 7:56we're dragging it but then once we let
- 7:57go it's not going to be anchored any
- 7:59anymore so if I were to demonstrate this
- 8:00to you let's change the shape of this
- 8:02part to let's say a ball like this and
- 8:06I'm also going to make it a little bit
- 8:07bigger as well so if I hit play and if I
- 8:10were to roll this around then it's going
- 8:12to be unanchored but then if I use the
- 8:14drag detector it's going to Anchor the
- 8:16part but then once I let go it's going
- 8:18to go and roll off into the distance
- 8:20again because that's what happens when
- 8:22you use a geometric response time with
- 8:24an unanchored part but with an anchored
- 8:26part obviously it's not going to roll
- 8:28around at all and so that's something I
- 8:30wanted to add there for response style
- 8:31and I hope that this analogy or this
- 8:34explanation has helped you so far to
- 8:36understand it so now let's move on to
- 8:38the next part another important property
- 8:39we need to know here is the drag style
- 8:42and basically what this does is it
- 8:44determines how we want to drag this part
- 8:47that's inside of the game and there's a
- 8:49lot of options here to tell you what
- 8:52kind of style you want to have for your
- 8:53dragging and I'm going to go over some
- 8:55of the important ones here but let's try
- 8:56and break this down conceptually so if
- 8:58let's say I had this part and I wanted
- 9:00to move it alongside the X AIS which is
- 9:03in this direction or if I wanted to move
- 9:06it alongside the zais which is in this
- 9:08direction or if I wanted to drag it
- 9:10inside of the y direction which is uh up
- 9:12and down or if I even want to add a
- 9:15rotational element to this as well then
- 9:17we can do this by determining the drag
- 9:20style of where we want the part to be
- 9:24draggable towards basically so that's
- 9:27what we can do here with this drag style
- 9:29and and uh the first one I'm going to
- 9:30show you is called translate line and
- 9:33basically this drag style gives a
- 9:36one-dimensional motion alongside the
- 9:39drag detector's axis now I'm going to
- 9:42show you a little bit later how we can
- 9:43configure this direction in a little bit
- 9:46but by default the one-dimensional axis
- 9:49is in the y direction so if we were to
- 9:52use translate line then this is going to
- 9:54go up and down like this inside the Y
- 9:56AIS so if I were to just quickly change
- 9:59the response style back to physical and
- 10:01we need to make sure that our part is
- 10:02not anchored okay it's not anchored so
- 10:04if we now hit play then I'm going to
- 10:06show you what translate line looks like
- 10:08so it's going to only go up and down
- 10:11inside of the Y AIS because we specified
- 10:15translate line to be a one-dimensional
- 10:19motion alongside the drag detector's
- 10:21axis which is the y axis so now if we
- 10:24hit stop I'm going to show you the
- 10:26second drag style which if we go down
- 10:28here it's called transl plane which is
- 10:30basically a two-dimensional motion
- 10:33dragging style that goes along the axes
- 10:37that are perpendicular to the drag
- 10:40detector's axis so basically what I mean
- 10:42here is the drag detector's axis is in
- 10:45the y direction by default so that means
- 10:48the translate plane axes are going to be
- 10:51the ones that are going to be the
- 10:52opposite of the y- AIS so it's going to
- 10:55be in the x-axis and it's going to be in
- 10:57the z-axis not the Y one so if I were to
- 11:01go into the game I can show you this uh
- 11:03just by testing it so translate plane is
- 11:06going to allow me to drag it in the x-
- 11:07axis and it's also going to allow me to
- 11:09drag it in the z-axis just not in the y
- 11:12axis because that's what the axis for
- 11:16this drag uh detector currently is I
- 11:18hope this part is making sense so far
- 11:20once again I will show you how we can
- 11:21configure the drag Direction just a
- 11:23little bit but I hope so far this analog
- 11:25has been helping you understand these
- 11:28different uh drag styles
- 11:29so if I were to now hit stop and go to
- 11:31this drag detector there are some other
- 11:33ones that are pretty useful like rotate
- 11:35axis this is what allows you to have a
- 11:39rotational element to dragging your drag
- 11:42detector around just like this so it's
- 11:44not going to move but instead it's just
- 11:46going to rotate in place so I think
- 11:47that's another useful one and then one
- 11:49more that I'm going to show you is
- 11:51translate view plane which basically
- 11:54takes the part and it drags it alongside
- 11:58the player's screen so if I were to drag
- 12:00this alongside here then it's basically
- 12:02going to follow um where the view frame
- 12:06of the camera is inside of the game and
- 12:09so that is basically what translate view
- 12:11plane does so if I was uh let's say in
- 12:14first person then it's just going to
- 12:16drag alongside wherever the camera or
- 12:19the view frame is and so that is
- 12:21basically something that that would be
- 12:23pretty useful to have for this kind of
- 12:25drag style so those are some of the drag
- 12:27Styles I wanted to go over here but now
- 12:30but before I go over some of the other
- 12:32ones there is something else we need to
- 12:33know about first so there are other drag
- 12:35Styles here called translate line or
- 12:37plane or translate plane or line and you
- 12:40might be thinking what are these drag
- 12:42Styles well I can't exactly explain
- 12:44these drag Styles unless we understand
- 12:46another concept when it comes to drag
- 12:48detectors and that is called mode
- 12:51switching down here now basically what
- 12:53mode switching is is it allows the
- 12:55player to hold down a certain key to
- 12:59have this sort of modifier input to be
- 13:01able to change the drag style Midway
- 13:04while they're dragging a specific part
- 13:07so basically for PC we have to press the
- 13:10left control key to be able to switch
- 13:14our drag style Midway while we are
- 13:16dragging a certain part so with these
- 13:19certain drag Styles here with translate
- 13:21line or plane or translate plane or line
- 13:23if we were to let's say select translate
- 13:25plan or line basically what this is
- 13:27saying is for our
- 13:29primary drag style it's going to be
- 13:31translate plane that allows us to go on
- 13:34the x and z Direction but if we were to
- 13:37hold down this modifier input then it's
- 13:40going to switch the drag style to our
- 13:43secondary drag style which is translate
- 13:46line and that is basically what this is
- 13:48trying to say here so if I were to hit
- 13:50play I can show you what this looks like
- 13:51in game so our primary drag style is
- 13:55translate plane so it's going to go in
- 13:57the x and z Direction but if now let's
- 14:00say I held down the modifier input key
- 14:02which is left control like so and then I
- 14:05drag it then it's going to go up and
- 14:08down because it switched the drag style
- 14:10to go to our secondary drag style
- 14:12instead of our first one and then if I
- 14:14let go then it's just going to go back
- 14:15and switch to the primary drag style so
- 14:19that is uh something I wanted you to
- 14:20know about and it basically works the
- 14:22same way with translate liner plane it
- 14:24starts with translate line first but
- 14:27then once you press down the modifier
- 14:29input then it's going to switch to
- 14:30translate plane and I hope that this has
- 14:32made sense to you so for this next part
- 14:33we're going to change the physics of a
- 14:35drag detector and so before we do that
- 14:37what we're going to do is go to model
- 14:39and we're actually going to create a new
- 14:41part so let's hit the drop down here and
- 14:43let's insert a sphere like this and what
- 14:46we're also going to do is create a new
- 14:48drag detector and put it inside of this
- 14:49part so I'm going to hit the plus sign
- 14:51and I'm going to insert a drag detector
- 14:53just like this and so basically what
- 14:55we're going to change here is if we
- 14:57scroll down here the phys physics
- 14:59response category with all these
- 15:01properties that are associated with it
- 15:03and so if you remember what I mentioned
- 15:05earlier in this episode The response
- 15:07Style with physical is basically what
- 15:10allows physics to be incorporated with
- 15:12the dragging of this drag style and so
- 15:15it's determined through these properties
- 15:17down here with apply at Center of mass
- 15:20Max Force Max torque and responsiveness
- 15:22now you might be confused with what all
- 15:24these properties mean so I'm going to
- 15:25try and explain each one of them to the
- 15:26best of my knowledge but basically Max
- 15:28Force
- 15:29determines how much force we want to
- 15:32apply to this part to be able to reach
- 15:35its goal and this is the maximum that
- 15:37we're going to give it so if it's
- 15:39anything that's after this number then
- 15:42it's basically going to be too fast and
- 15:43we don't want it to exceed the max force
- 15:46but this is actually a very very large
- 15:48number and that's actually the reason
- 15:50why it can go off into the void so
- 15:52easily because of it so what we can do
- 15:54is actually decrease this Max Force from
- 15:5610 million to let's say uh 10,000
- 16:00instead and so if we go hit test and hit
- 16:02play then what we should see is if we
- 16:05drag this part around then it's not
- 16:07going to go off into the void as it was
- 16:10able to before it it's kind of taking
- 16:12its time just a little bit but if we
- 16:14want to really see the change then we
- 16:16can actually decrease this even further
- 16:18to let's say 1,000 then it's going to
- 16:21make it even slower because we're uh not
- 16:24going to be applying a super big Max
- 16:27Force to be able to reach the goal that
- 16:29we're trying to make it reach towards so
- 16:31that is what Max Force basically does it
- 16:33limits how much force we can apply at
- 16:37any given time for it to reach its goal
- 16:39and that's basically what it is so the
- 16:40next property is Max torque which is
- 16:43basically the rotational counterpart to
- 16:46Max Force so max force deals with how
- 16:49much force is either being pushed or
- 16:50pulled but this basically determines the
- 16:52rotational aspect of it which is how
- 16:55fast or how slow a part gets rotated
- 16:57around like so and torque is basically
- 17:00how much of it do we want to maximize
- 17:02before it reaches a certain point where
- 17:03we don't want it to go even faster than
- 17:05it than it should so that is basically
- 17:08what Max torque is and responsiveness is
- 17:10how fast do we want this part to respond
- 17:13to this new location that we're trying
- 17:15to make it go to so a good way to think
- 17:18about this is the higher the number of
- 17:19responsiveness the more responsive it is
- 17:22you know like how it's like quicker to
- 17:25reach the goal that it needs to reach
- 17:27towards so if we were to make the Max
- 17:29Force let's say uh 10,000 and we were to
- 17:32change the responsiveness to 100 so it's
- 17:35it's rapidly more responsive than it was
- 17:37before then it's going to reach the goal
- 17:40a lot faster as you can see here it's
- 17:42it's basically almost instantaneously
- 17:45going to uh the direction or location of
- 17:47where my mouse is going and that's
- 17:48basically what responsiveness does it's
- 17:51how fast do we want this part to be able
- 17:54to reach its goal without having to
- 17:57exceed the max torque or max force that
- 18:00we specified this part to be and I hope
- 18:02that some of these properties have been
- 18:03making sense to you and it honestly just
- 18:05comes down to experimentation to see
- 18:07which one works best for you but this is
- 18:10a little small introduction to some of
- 18:11the properties but there is one more
- 18:13property here called apply at Center of
- 18:16mass and basically what this does is do
- 18:18we want to have the force or the the
- 18:21focal point of the uh of the physics be
- 18:24involved with the center of the part
- 18:27that we're trying to change or is it
- 18:29going to be where our Mouse is located
- 18:31when we're dragging it so if I were to
- 18:33set this property to be true and if I
- 18:35were to go into the game then I can show
- 18:36you what this looks like visually so if
- 18:39I were to let's say hold the part on the
- 18:41left side here then it's going to move
- 18:42the part to the center of where my mouse
- 18:46is located so if I let go and then try
- 18:48this again on the right side then it's
- 18:49going to move the the center of Mass to
- 18:52where my mouse is located now if I were
- 18:55to disable apply at Center of mass again
- 18:58then it's going to make the uh Center of
- 19:01mass be wherever my mouse is currently
- 19:04now there's one thing you may or may not
- 19:06have noticed but if we let's say change
- 19:08the response style to geometric then the
- 19:11category for physical response is gone
- 19:13obviously because if we're working with
- 19:15the geometric response style then we're
- 19:17not applying physics to this part so
- 19:19that's why this category will only show
- 19:22if we have a response style of physical
- 19:24so that's one thing I wanted to add
- 19:26before uh we move on to the next part of
- 19:28this episode and I hope that you found
- 19:29these properties to be useful so I
- 19:31mentioned earlier in this episode we can
- 19:32change the drag direction of a drag
- 19:35detector for a part and basically what
- 19:37I'm referring to is by default if we
- 19:39remember the axis so if we go down here
- 19:42inside the drag directions category
- 19:44there's this property called axis and by
- 19:47default the axis for this drag detector
- 19:50is in the Y AIS so when we started with
- 19:53translate line as our drag style it's
- 19:56giving us a one-dimensional motion
- 19:59along the axis of this drag detector
- 20:02which is in the y direction but we can
- 20:04actually change this drag direction to
- 20:06be something that's not in the Y AIS but
- 20:08instead let's say in the xaxis or the
- 20:11z-axis so if I were to change the y-
- 20:14axis to zero and if I were to change the
- 20:18uh let's say x AIS to one so if we hit
- 20:21enter just like this then what we should
- 20:23see is if we go into the game and hit
- 20:26play then we should be able to drag our
- 20:29part alongside the x axis for our
- 20:32translate line dragging style since it
- 20:34gives us a one-dimensional motion
- 20:36alongside the axis but it's no longer a
- 20:38part of the Y AIS Dimension because we
- 20:41changed it so we can do the same thing
- 20:43with let's say Z so if we were to change
- 20:46X back to zero and then we were to
- 20:47change Z to one then we're going to hit
- 20:49play and then it's only going to go
- 20:51alongside the Z AIS just like this and
- 20:54nowhere else and we can do some pretty
- 20:56interesting stuff here with let's say if
- 20:57we were to change the the drag style to
- 20:59translate line or plane if you remember
- 21:02with translate plane it's the two axes
- 21:05that are perpendicular to the axis so in
- 21:09this case our axis is now Z so if
- 21:12whatever so the axes that are
- 21:13perpendicular to it are X and Y for
- 21:16translate plane so if we were to go and
- 21:18hit play then it's going to start in the
- 21:21Z axis for translate line but then if we
- 21:23hold down our input modifier which is
- 21:25left control then it's going to switch
- 21:27to translate which is the y direction
- 21:31and also the X Direction so it's going
- 21:33to go something like this and it
- 21:35honestly requires a bunch of uh
- 21:37experimentation to try and figure out
- 21:39what works best for you when it comes to
- 21:42changing the drag Direction and I want
- 21:44you to keep note of this if you do
- 21:46decide to change the drag direction of a
- 21:48drag detector it depends on what your
- 21:50needs are so this honestly requires some
- 21:52experimentation but I hope that you
- 21:54found this part to be pretty informative
- 21:55so far now there's another thing you may
- 21:57have noticed and that is when whenever
- 21:58we're changing our axis it's also
- 22:00changing a bunch of these properties
- 22:02down here but I think an important one
- 22:04to know is the orientation here so this
- 22:07is another Vector 3 value which gives us
- 22:09an X Y and Z value that basically
- 22:11determines if we were to have a
- 22:13rotational drag style so if you were to
- 22:15change this to rotate axis this is the
- 22:18direction that this part is going to go
- 22:21if we decide to rotate it and the way we
- 22:23can really see this is if we were to
- 22:25change the response style to geometric
- 22:27because if we were to use physical then
- 22:29we won't be able to see the changes
- 22:30properly because it's being affected by
- 22:32uh the physical constraints so if we
- 22:34were to drag this then it's going to
- 22:36drag like this which we specified the
- 22:39orientation to be but if we were to
- 22:41change the axis to Y so if I were to
- 22:43make z0 and then y to 1 then it's going
- 22:47to change the orientation again and this
- 22:48is going to have a different rotational
- 22:51Direction uh for this part just like
- 22:54this and so Roblox will automatically
- 22:56configure the orientation or the axis if
- 23:00you change either one of those two and
- 23:01that's another thing I want you to
- 23:02consider when it comes to those sorts of
- 23:05things and so I hope you found this part
- 23:06to be helpful for this next part I'm
- 23:07going to be introducing movement limits
- 23:10which basically allows us to have a
- 23:12certain limit of how far we can drag
- 23:15something out before it reaches a
- 23:17certain point so I created this little
- 23:19drawer example here where we basically
- 23:21drag this middle part outward like this
- 23:24and then once we reach a certain point
- 23:27then it's not going to be able to be
- 23:29draggable past this certain point right
- 23:31here but instead we could just drag it
- 23:33back inside like this and it can't go
- 23:35outside this way as well so this is the
- 23:38only space that we can allow movement to
- 23:41happen with this drag detector and so
- 23:43we're essentially going to be recreating
- 23:44this drawer system right here so I'm now
- 23:46going to hit stop so we can go ahead and
- 23:48recreate the system all right so what
- 23:49I'm going to do is go to model we're
- 23:51going to go down to part and we're going
- 23:53to insert a block like this and I'm just
- 23:56going to scale the part just like this
- 24:00and I'm also going to change the color
- 24:04to let's say this reddish brown color
- 24:07and what I'm also going to do is
- 24:09duplicate this part to make it go up
- 24:11like this and I'm also going to
- 24:12duplicate it one more time just like
- 24:14this and I'm I'm actually going to take
- 24:16all these parts and I'm going to right
- 24:18click and I'm going to group as a model
- 24:21like this and I'm just going to call
- 24:23this drawer like that and so now what
- 24:26we're going to do is if we open up this
- 24:28there is going to be the middle part
- 24:29which should be this one right here so
- 24:32I'm going to call this one drawer and
- 24:35I'm also going to change the color of
- 24:38this drawer to let's say black just to
- 24:40differentiate it and what I'm also going
- 24:42to do is specify this top right here as
- 24:45well and this is going to be important
- 24:47later and I'll show you why so what
- 24:49we're going to do for the drawer is hit
- 24:50the plus sign we're going to insert a
- 24:52drag detector like this and there's
- 24:55going to be a few important things we
- 24:57need to do first so one thing is for our
- 25:00parts that are not the drawer we're
- 25:02going to go down and we're going to
- 25:04Anchor them because we're not going to
- 25:05make them dragable and then for this
- 25:07drawer what we're going to do is for
- 25:10this drag detector we're going to make
- 25:12the response style geometric and we're
- 25:15also going to make the drag style
- 25:17translate line because we only want it
- 25:19to go in One Direction here so that is
- 25:23basically what we have going on so far
- 25:26and what we also need to do is change
- 25:28the axis of the drag Direction because
- 25:31by default it's in the y direction so if
- 25:33we left it as is then it's only going to
- 25:35be able to go up and down but we want it
- 25:37to go in the X Direction like this so we
- 25:40are going to essentially go to the drag
- 25:42detector we're going to change the axis
- 25:46to have one as the x axis and then zero
- 25:49as the y axis just like this and so
- 25:53basically that is essentially what we
- 25:54have going on so far so if we hit play
- 25:56here then we should basically be able to
- 26:00drag this alongside the X Direction but
- 26:02you may have noticed there is no limit
- 26:04to how far we can drag this thing and
- 26:07this is basically where dragging
- 26:09limitations come in and that's what
- 26:10we're going to be adding here so if we
- 26:12hit stop then there's this section here
- 26:14called drag limits and there's two
- 26:16properties that's going to be important
- 26:17for us here the first one is Max drag
- 26:21translation and then this one is min
- 26:23drag translation so with Min and Max
- 26:25basically with these coordinates how far
- 26:27do we want to be able to drag this part
- 26:30in a certain direction which is the max
- 26:32and minimum is how far do we want to be
- 26:34able to drag this in the opposite
- 26:36direction now here's one thing you have
- 26:38to be very careful about here so if
- 26:40we're going in the X Direction it goes
- 26:44incrementally this way so it's going to
- 26:47increase the number ever so slightly if
- 26:49you notice the positional value on the
- 26:51right side here it's increasing in this
- 26:53direction but what we want is for this
- 26:57to go in the opposite direction here as
- 27:00you can see the position is going
- 27:02further down the list so instead of
- 27:04using Max drag translation we're
- 27:06actually going to use Min drag
- 27:08translation because this is how far we
- 27:12can go in the opposite direction I hope
- 27:14that that part is making sense so
- 27:16basically what we're going to do here is
- 27:17for the Min drag translation we're going
- 27:19to set this to five in the X Direction
- 27:21and we're not even going to change
- 27:23anything in the Max uh drag translation
- 27:25because we're not concerned about what's
- 27:27happening over over here in this
- 27:29direction but instead if we have the max
- 27:31translation to zero then we can't go
- 27:34anywhere past this point here so if we
- 27:37now hit play Then basically what we
- 27:39should see is that we can drag uh oh
- 27:44hold on hold on I messed something up
- 27:46here okay okay so there's a little typo
- 27:49here this should be -5 for the minimum
- 27:52translation and not five because we're
- 27:55going to be going in the opposite
- 27:56direction and that's what's going to
- 27:58be changed with the X direction is that
- 28:00it's going to go down further this way
- 28:02so if we now drag it all the way back
- 28:04here then there should be a limit to how
- 28:07far we can go back and obviously the
- 28:09constraint for going on the right side
- 28:11is nothing it's just going to be at zero
- 28:13so this is all we can do for this
- 28:16dragging which is exactly what we want
- 28:18but unfortunately we're not done here
- 28:21and I will show you why so there's
- 28:23something in the documentation where
- 28:25they mention how dragging limits is not
- 28:28not the same thing as constraints so
- 28:30basically what I'm referring to here is
- 28:32if we drag this this is how far we can
- 28:35drag this part within a specific drag
- 28:38but if I let go and then I drag it again
- 28:41then oh you see you see what happened
- 28:44there it's now dragging past where it
- 28:46needs to go because once my drag is done
- 28:50then it basically resets the maximum or
- 28:53minimum uh limit that I had with this
- 28:55drag detector so when you're in a
- 28:57situation like this how would you
- 28:59exactly fix this well there is most
- 29:01certainly one way we can fix this and
- 29:03this is with the use of a reference
- 29:05instance so I'm going to show you what
- 29:07this is uh right now so in order to fix
- 29:09a problem like this we need to have
- 29:10what's called a reference instance which
- 29:13is basically an instance that this drag
- 29:15detector is applied to that gives the
- 29:19reference frame that we are going to use
- 29:22to determine if our drag has exceeded
- 29:26this reference position or frame or
- 29:28whatever it is that we're trying to use
- 29:30here and the reason this is important is
- 29:32because let's say we were to drag this
- 29:33part alongside here then the reference
- 29:36is still inside of the middle of this
- 29:39part that's right over here with this
- 29:40drag detector so the only reference that
- 29:42it has is the center of this part so
- 29:45because the reference is here we can go5
- 29:48studs back down this way but the
- 29:51position keeps changing so what we need
- 29:54is a reference that stays in place with
- 29:57this drawer dra so that it actually
- 30:00doesn't exceed that position and so I
- 30:02hope once you understand it this way
- 30:04then you can probably see the importance
- 30:06of having a reference instance for this
- 30:08but you might ask what kind of reference
- 30:10instance are we going to have for this
- 30:11drag detector well we can most certainly
- 30:14use something that pertains to this
- 30:16drawer like this top part that I said
- 30:19was going to be important later because
- 30:21this gives us a reference frame for
- 30:24where the drawer is located so basically
- 30:26the way we're able to do this is if we
- 30:28take the drag detector there's this
- 30:30property called reference instance so if
- 30:31we select this then we can select the
- 30:33instance that we want this reference to
- 30:35be a part of so what I'm going to do is
- 30:37select the top part here so now once
- 30:40we're able to do this then this
- 30:42basically gives us a reference point of
- 30:45where we want this part to be able to
- 30:48move uh far away from but not too far
- 30:50away from this reference point so that
- 30:52is the only thing we need to do here so
- 30:54now if we hit play then what we should
- 30:56see is if we drag this part alongside
- 30:58here then we can't drag this further
- 31:01along because it's not going to go past
- 31:05the reference frame point of this top
- 31:07part here it's not going to go past it
- 31:09and also I noticed that this is
- 31:10glitching out a little bit and that's
- 31:11probably because it's a good practice to
- 31:13make these parts anchored when you're
- 31:15doing a reference style here so that is
- 31:16basically how we create a drawer system
- 31:18using these drag detectors now if I were
- 31:21to rotate this part alongside this
- 31:23direction then it's not going to affect
- 31:26the axis whatsoever and we're still able
- 31:28to make a drawer system work just like
- 31:31this and I hope from my explanation and
- 31:33also from everything we've learned up
- 31:35until this point that uh you were able
- 31:37to get a good understanding of how these
- 31:38drag detectors work now there are
- 31:40scripting events we can use to detect
- 31:43certain things like did the player start
- 31:45dragging this part or is the player
- 31:48still dragging this part or did they
- 31:50stop dragging this part uh we can do
- 31:51that there a script so what I'm going to
- 31:53do is go to the drawer and we're going
- 31:54to hit the plus sign and we're going to
- 31:56insert a script like this so so I'm
- 31:58going to make reference to the drag
- 32:00Detector by saying local drag detector
- 32:04equals script. par. drag detector like
- 32:06this and what I'm going to do here is
- 32:08say drag detector.
- 32:11dragstart colon connect function open
- 32:14close parentheses enter and there are a
- 32:16lot of parameters that does get past
- 32:19here but the one that we're going to be
- 32:20focused on is the player who did drag
- 32:22this part so we're going to pass in the
- 32:24player and we can just print something
- 32:26like player. name concatenate with has
- 32:30started dragging like this and then
- 32:33there's other events like drag detector.
- 32:36drag continue colon connect function
- 32:39pass in the player like this and we
- 32:41could just take this print statement and
- 32:43paste it down here is still dragging
- 32:47like this and then finally there's
- 32:49another one called drag detector.
- 32:51dragend colon connect function open
- 32:54close parentheses
- 32:56player enter and then we can basically
- 33:00copy this paste down here has ended or
- 33:03has stopped dragging like this so drag
- 33:07start it only fires once once the player
- 33:09actually does start dragging this drag
- 33:11detector drag continue is going to
- 33:14repeatedly print this statement out for
- 33:16every frame that the drag is being
- 33:19dragged across the screen and the drag
- 33:21end is only going to fire once once we
- 33:23let go of the drag so if we were to test
- 33:26this out in game then we can hold uh the
- 33:30drag and then it's going to print in the
- 33:31output saying brawl battle has started
- 33:33dragging and then once we drag it's
- 33:35going to continuously print the
- 33:37statement for every time that the frame
- 33:41for this dragging changes and then once
- 33:42I let go then it's going to say brawl
- 33:44battle has stopped dragging and there's
- 33:46other ways we can get information about
- 33:49this drag using a property and this
- 33:52property is called drag frame down here
- 33:54which basically consists of two values a
- 33:56positional value and an orientation
- 33:58value and this tells us what position
- 34:01this drag is currently taking place in
- 34:04and then once we let go of the drag
- 34:05that's when it resets back to zero for
- 34:08both position and orientation so we can
- 34:10do that down here by detecting it by
- 34:12saying drag detector colon get property
- 34:16changed signal open and close
- 34:18parentheses and then whatever the
- 34:19property is here which is drag frame and
- 34:22then we're going to connect this to a
- 34:24function so connect function open close
- 34:27parentheses please enter and we can
- 34:29basically get any information we want
- 34:31from this drag frame so we can let's say
- 34:33print out the drag detector. drag
- 34:38frame. position just like this and this
- 34:41is something we can print out obviously
- 34:43there's other things we can print here
- 34:44like the orientation or there's even
- 34:46more specific things we can do so drag
- 34:49frame. position do uh magnitude unit and
- 34:52if we don't want the position then we
- 34:53can have something different like the
- 34:54look vector and all these other sorts of
- 34:56vectors here but but let's say we want
- 34:58to locate the position so I'm going to
- 35:01comment out this drag continue event
- 35:03here and now we're going to hit play so
- 35:05we should be able to see what happens to
- 35:07the position of the drag whenever we're
- 35:09moving alongside the X Direction it's
- 35:12slowly yet surely decreasing the X
- 35:17position of this part right here and so
- 35:20that is something I want you to take
- 35:21away from this and as you can see the
- 35:23limit came down to when it reached ne5
- 35:26and we can't go down any further past
- 35:27this point and then if we make it go
- 35:28back down this way then it's going to
- 35:30reset back down to zero and that is
- 35:32essentially some pretty useful things we
- 35:34can use when it comes to scripting these
- 35:36drag detectors and I hope you found this
- 35:37part to be helpful so that is basically
- 35:40the introduction to drag detectors now
- 35:42there are some things I did not get to
- 35:43cover in this episode like permission
- 35:46policy which is basically which player
- 35:48can drag this part or if anybody can
- 35:51drag this part as a matter of fact and
- 35:52then there's other ones like whether we
- 35:55can run this locally on the player side
- 35:57so so that no other player can see the
- 35:59dragging that's happening I will let you
- 36:00experiment and try these things out for
- 36:03yourself but I think for the most part I
- 36:05was able to at least get you to try
- 36:08these drag detectors out for yourself
- 36:10and I hope that you found this video to
- 36:11be very very informative and I
- 36:13definitely enjoyed making this episode
- 36:14now before you go I want to give a shout
- 36:16out to my second and third patreon
- 36:18members boopy your noose and tri vjf but
- 36:22he likes to go by T for short for
- 36:24directly supporting me through my
- 36:25patreon and it's h honly just it's very
- 36:28heartwarming to see that there are
- 36:30people where I've impacted them so much
- 36:32through my videos that they'd be willing
- 36:34to support me through my patreon and
- 36:36that is something I I really love to see
- 36:38and I and I can't be more grateful that
- 36:40I have people who are like that um but
- 36:43anyways if you want to do the same thing
- 36:44for me I will leave a link to my patreon
- 36:46page in the description where you can
- 36:48get access to all of my scripts and
- 36:51assets that I've created throughout this
- 36:53entire series and you can also get
- 36:55access to videos early for everyone else
- 36:58and maybe some additional bonus content
- 37:01that I will occasionally put out on on
- 37:02my patreon as well so go ahead and check
- 37:04that out and with that I will now
- 37:06conclude this episode I will see you in
- 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.