Roblox Studio HOW TO MAKE A PART MOVE IN A SPIRAL AND CIRCLE | Sin Cos Rad Tutorial.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i'm going to be showing you guys today how to make something super cool like this so it's just a demonstration of what you'll be learning throughout the video so make sure to stick around to the end because you learn tons of cool stuff hey guys so i'm going to be showing you how to actually use the sine and cosine functions in roblox studio a more practical way of using it so as you can see i have an image up on my screen right now this is called the unit circle now don't suck yourself out too much looking at this because it does take a while to get used to and get to know it but you only need to know kind of one key feature of this right and that's that it's a circle so how do we actually navigate around the circle i'll be actually going to roblox studio soon and showing you how we can make the circle in a game so we'll have an object basically just spinning in circles and doing cool things so as you can see it says 30 degrees here 45 degrees 60 degrees all that fun stuff so that's with our normal cartesian coordinate right so when we're trying to find the degree of an angle we usually just say 30 degrees but with the unit circle we're going to be converting that to radians so that's why we use the math.rad function in roblox studio so that means math.radians so we're going to be translating 30 degrees to radians which will equal pi over 6 and that is this little 30 degree angle right here so as you can guess i'm just going to have like a while loop counting up in degrees so like 1 degree 2 degree 3 degree and it's just going to be navigating around the circle and i'll show you what i mean here in a second so again if i do cosine 45 degrees cosine is always represented by the x-coordinate up here so if i do cosine of 45 degrees that's going to show me square root of 2 over 2. if i do cosine of 120 degrees radians of course negative one over two if similarly if i do cosine of two pi over three that's also going to give me negative one over two so we're not actually going to be writing in 2 pi over 3 we're just going to be using the degrees converting that to radians and it's going to give us these coordinates so now if i have both the cosine and sine coordinate it will just give me this exact angle on the unit circle as you can also see if i do sine of 2 pi over 3 it's going to give me square root of 3 over 2. if i do cosine of 135 degrees it will give me square root of 2 over 2. if i do sine of 135 degrees will give me this y coordinate square root 2 over 2. so i'm going to hop into roblox studio now i'm going to show you some cool stuff we could do with this so now i'm back in roblox studio right hence now you see i have a little object spinning in circles i'm only able to do this because of the unit circle right if i didn't have the unit circle to work with it would be very hard just to trace a circle like this and i can actually do so many more cool things with this than just trace a circle like i could have it go in a spiral and this is all thanks to like vectors and stuff and just like physics in general because it allows us to kind of simulate like a spiral it's really cool i'll show you so as you can probably guess i just have a while loop running infinitely just a while true loop and it is basically just saying while true degrees plus or equals one so i just have a degree counter and that's increasing by one every time the while root while loop increments so now it's just going through the circle infinitely converting a degree to a radian so i'm going to actually type out the script so um you guys can follow along with that here we go so i'm going to create a part over here and i'm just going to name this part um moving part two you guys can name this moving part or just moving if you want it doesn't really matter it doesn't really matter what you haven't named but um i'm just going to name it name it moving part 2 for now so now what i want to do is anchor this so it doesn't fall over and stuff like that we don't want that and i'm going to go into my click this little plus sign in the explorer type in script and now here we go we got the basic print hello world here so now what i'm going to do is i am going to just get the part that i want to move script up parent that redirects me to my part up here and now i'm going to also define the run service so actually let me type this out hopefully if you don't know we'll run insert but sorry what run services it allows you to actually um it's not a b test service it allows you to i don't know why i can't type right now get the render steps rb all that stuff i want to use heartbeat which will take place of just a weight i don't want to use weight i'll show you what i mean here in a second so if i do while run service and then i could just do oops run service dot heartbeat weight this will wait one heartbeat on the server i'm not going to fully explain what a harpy is but it is very fast i'll tell you that so instead of using a weight i'm going to use this because it will run a lot more smooth if i do it this way so another thing i want to do is i'm going to initialize the degree variable i'll set that to 0 right now and every time this will loop it goes through this loop i'm just going to have it increment the degrees by one so it's just going to keep going keep incrementing this infinitely almost that's not going to matter because on the unit circle it's always going to go back to 0 once it hits 360 you won't see that though so i'm going to now type in local x so this is going to be my x coordinate for my circle so it will just be moving if i look at my position vector down here there it is i'm going to have this x position right here it's going to be moving kind of over while the sign will make it go up and stuff it's it's weird you'll see what i mean in a second though so if i do local x equals math dot cosine just like i said the x the x vector we'll have the math.cosine function running because we're grabbing that x coordinate so now once we have that we're going to convert to radians the degrees so again if you're still confused you could rewind the video go back to the beginning and see what i was talking about with grabbing the x-coordinate from the unit circle so this is just going to make it so it moves horizontally and now i'm going to initialize a y vector math.cosine sorry this one's going to be sine and then we'll convert this to degrees so now we have the circular motion going and finally we're just gonna have it a z one that's just gonna be constant we don't want that changing so now all we do is do part.position equals vector3.nu x comma y comma z because we already have these all defined so now if i run this let's see if everything works ready it actually might move over here so let's just see what happens so i run my game comes over here as you can see it is actually moving in a circle it's not moving very um like a large gap so we're gonna change that real quick so i'm gonna make it so it moves on a wider just it's gonna have a wider radius it's not gonna be so tight so to make it have a wider radius all we have to do is multiply a number by this so this will um kind of expand it out so we can see the change immediately just like this so now it's a larger circle it's going under the base plate though i'm going to actually fix that real quick too so just to kind of offset this i'm going to say plus 11. this will just offset the y position up 11 so we don't have to worry about it going through the base plate so as you can see now it's not going through the base plate and it's moving a circular motion just like the unit circle again i don't fully expect you to understand the unit circle unless you have a lot of experience all you have to know is that cosine will move along the x position and sine always grabs the y position so again if you want if you're curious about the unit circle stuff like that that's all trigono that's mostly trigonometry yeah so once you get into your pre-calc courses in high school or calculus you do so much of the unit circle it's ridiculous like you'll have that thing memorized like i have the i could list out the whole unit circle so easily so just to um make this a bit easier to see i'm going to give this a white color and i will make it neon so now that we have this neon i'm also going to scale this down like we did the previous part i'm just going to add a trail to it trail attachment one attachment two piece of trail needs two attachments remember that so i'm just gonna move these attachments so they fit this a little bit better and now i'm going to attach make these attachments like that so i'm going to also change up the trail so it just you can see it better it's going to emit one light and i'm going to change the color of it actually i'll leave it i love it like end off grayish so we could see it moving in the circular motion better there we go so let's see what happens now it shouldn't look too much different it really should just like add a nice cool effect to it went all the way over there look at that it kind of looks like um if you think about it it looks like a nice little loading screen and we could also change the lifetime of this we could change the lifetime to like 10 seconds and it will stick around for longer i'm also going to make it so faces the camera there we go so let's see what this does it keeps going over here so check that out as you can see it kind of um traces the outline of the circle it's super cool looks like a little loading screen so one more thing i want to do before i end off this video is a very quick tutorial so um i exp like if you guys really want to understand cosine sign all that stuff you're going to have to do a little bit more research on your own because that would take a lot more time so i'm just showing you the effects you can have in roblox studio uh one more thing i want to do is i'm going to actually um i'm going to make it move a bit faster if you want the circle moving faster you can actually just change the degrees so it's just spiraling faster and you can actually make this z coordinate you can make this go by degree divided by 10. so this will just make it so it's moving along the z-axis and not a constant number but now it's moving as you can see it's moving in a spiral so you can actually use this like i might have a tutorial in the future making an attack using the math and cosine functions like this so if you guys like this video you know please like please subscribe you can tell me what is doing right or wrong i know i kind of explained it rather quickly but um i haven't made a video in like two weeks because i've been super busy with school that's how it is so um i hope you guys can like understand that but um yeah you guys can always play around with these numbers you can also make this a really huge circle just by um doing that you can even make it look like an ellipse if you change one of the numbers to be different like look at that circle oh my gosh now it's spiraling like a that looks super cool let's actually let me test something real quick so if i do this i think this should make it look like an ellipse almost oops let me get rid of the um let me make this constant again and let me make this a bit smaller so yeah it's moving like um kind of looks like a football now it's an ellipse instead of a circle so yeah you can do a ton of cool stuff basically whatever you want you can do it so um i really appreciate you guys um thanks for watching and have a great day
Info
Channel: Joel__
Views: 25,102
Rating: undefined out of 5
Keywords:
Id: HcOjv6XlAmw
Channel Id: undefined
Length: 13min 58sec (838 seconds)
Published: Sat Oct 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.