Stormworks Lua Radar Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone and welcome back to another storm works video in this video I'll be showing you how to use the radar components to get a functional video screen with a radar here in stomachs as always we'll go over the components that you'll need we'll show you how to wire with it up and then fun we'll show you how to encode the little book to actually get that right off on a screen in installments now if you're doing this videos kampala enemy i'll see like see any my future videos why they're dumb kind of like and subscribe button command below follow iconic comic content as soon as it gets posted so said let's get straight into it and get started with this tutorial so before we get started with this video a couple things to this point are first off this is not going to be a proper math lesson I'm not going to teach you exactly how math works I'll just be showing you the code that you will need to get the actual radar functioning here in stone works now of course if you want to go into more detail or if you know better code or better math together working beside what I'm doing fine be it obviously please comment and let me know in the in this video itself but this is what I found is work and it's pretty simple to follow and understand now before we can actually get started with working on the code we have a base here in the actual workshop itself now we're going to be building a small little control panel and that's where we're going to put our monitor and everything else that we need to actually work on along with that is let's go and get a screen on now the screen is where we're actually going to go and see our actual radar itself so I'm gonna be using a 2 by 2 screen here along with that is we'll need a way to switch the screen on so I'm actually just going to be going and using let's see let's go and use a so I could break it just over here that's a nice way to go and actually turn it on off and then lastly we will also need some electricity so I'm just going to grab a battery I'm gonna put a battery underneath here just to hide it and make it a little bit more simple and a little more nicely looking okay along with that because we're using a circuit breaker and not an on/off button we will need then to go and use a constant signal okay constant on-off signal and I'm going to play sort of live that means pretty much that we flip the switch it sends electricity to everything and it turns everything on at the same time now for the radar itself you could go and use any of the radars I'm going to be using just the standard radar just over here now one problem with this is you can is it actually does do a rotation inside the radar however it uses a 0.2 positive and a 0.2 negative it goes only in one way and very so what I prefer to use here is going to be a velocity pivot okay so you can see we have a velocity pivot here now you can see that the positive is facing the left and the negative is facing right we don't want that we want the radar to actually go clockwise to do that we're going to just invert it rotate it round and place it down okay and then finally we actually going to put our radar on I'm dangerous elevated a bit grab the radar just over here and okay so we have the components that we're going to need so far okay let's go and get everything hooked up to start with you can see we have our on signal which is going to turn our screen on electricity is gonna come from our battery go into our circuit breaker and then from the circuit breaker is going to turn the velocity pivot it's going to turn the radar and it's going to turn our monitor on at the same time okay quite basic so far along with that we also want to get our radar to turn on and we wanted to rotate now what we're going to be doing is we're going to say we want a rotation speed of around 0.1 okay so I'm gonna place another constant number here I'm gonna put it over here and I'm gonna hit the zero point one I'm happy with that speed obviously you can go and play with it and adjust it as you feel fits a speed isn't going to go into our rotation block yeah you can go and test us now if you want to it's pretty basic and pretty straightforward as it is right now we'll if you turn that on it turns the monitor and you can see it's not spinning that radar right over there if you want to always know what angle it's facing you could just add a couple blocks here during this example and you can see as we turn it it goes and turns it around like that now what we want to do is we actually want to find what number is coming out of that current rotation of that velocity pivot now to figure out what that number is going to be I'm just gonna go and grab a she'll display put it over here because I want to know what the number is okay so I'm gonna add that up there grab some electricity go and add it to that display spawn it in turn it on and you can see here 0.5 is the side and it's going to go all the way up to 1 there and it's going to continue going round and round and round so that's our number that's coming out of that okay so that's perfect okay so you can see it gets to in theory for one rotation it gets to one okay so zero all the way to one okay pretty straightforward on that so far now what we want to do is we actually want to start building our screen or Lua script up to work with that data okay so I'm going to go and grab my credit controller and we're gonna start with a brand new one properties I'm gonna increase it to a decent size okay I'm going to call it radar new okay along with that is let's go and start adding some logic so to start off with we want to get that number that's coming out of the varsity pivot so far in number input and that's going to be our rotation okay very basic basic so far the next thing we want to do is also know when we are actually hit something so when the radar has found something so once again input that's going to be target found okay along with that we also will need the distance of that number therefore that target that we've just gone and found from the radar okay so we've got those two things of course because we're also using video here we will need a video art so it's gonna grab the video and that's going to be to our screen okay so basic so far we'll probably need some more but let's go and just do radio video new okay add that in let's go write our new let's go and close that off let's go and find it in our there we go we just found it let's go and place it down and then let's see what we're missing from this okay so going over here you can see that well our current rotation is going to go into the screen here we also have our target found what else do we need elevation angle we're not going to do in this video target distance we do need signal strength we don't care about field view we don't care about and facing your we don't care about just yet okay so that's the basics of what we need so far so we have all those things there Danny concert Oh trusty we've done already but that all hooked up our video we can go and get connected and we don't have any video so let's go back into our actual processor and let's start writing a couple different things so the first thing we need of course is to separate all this art and get it all set up and ready now we want to also go and get our radar start to get built okay so radars just gonna go over here okay and we have our Lua scripts now guys but just FYI before we carry on this is bugged at the moment as you just saw right now when I highlight this apparently the devs are sourcing this art so just bear with this I'm during this video because it is at the moment in nine point six currently bugged okay now we can get let's leave this stuff pretty much most of stuff on the screen right now we don't need to get rid of we can leave most of it here okay because currently it's getting a number in it's getting a number art it's getting our screen with our screen height it's setting the color to green which is great and it's drawing a circle filled at the center of the screen now what we want to do is we want to have a radar which is also a circle at the center of a screen however we don't want to filled so unfurl it we're just going to get rid of that so currently it's drawing a um a circle at the center which is worth divided by two and hot followed by two at a radius of 30 now radius of 30 we don't want okay we want the same radius of the screen because I want to fill the whole screen with this radar now we can get the actual Lua script to do that for us to do it or we can do is our it's going to equal to width plus height okay so the width is 64 high to 64 that gives us a total of 120 128 and we're going to divide that by four okay to make a square okay along with that we can then replace the 30 with our okay now in theory that should go and work if we go and spawn everything in yes okay I just want to double check I think we connected everything that we need at the moment yeah we did perfect it's got a spawn that in and let's go check that we have a circle on our screen yep there we go you can see a perfect circle that exactly the same size of the actual screen that we're using which is a 2 by 2 that's also rotating which you don't you just yet so the next thing we want to do is we want to actually draw a line on our screen to show the rotation of our radar so as the rotate as the rotation of the radar goes around we want our actual line on our radar to go around at the same speed and same time okay so the next thing we're going to do is we need to go into our actual radar now we need a way to know what that actual screen is going or actually the radar what angle is going at so we can use the rotation of a velocity pivot to come into our lua script okay so we need to go and add a way to convert that number into composite to do that I'm just gonna use a composite right number place this down I'm gonna say we need 10 channels why not we'll start with 10 channels okay so we're gonna get our number in which is number 1 and that's gonna go in into our little script okay so we're gonna say that let's go with let's say our rotation is eight and that's going to equal to input get number one okay perfect let's copy and paste that they'll get input get number one great okay along with that is we're going to go now and start drawing our line so to draw our line we can grab that code right over there it's okay draw a line at X 1 or that's the center of our screen so that width divided by 2 and height divided by 2 and then we want to put the next point we want them to point on the actual circle okay now to get that you will needle would have math now the math that you will need as I said earlier this is not a math tutorial I'm not gonna explain how this works I'm just gonna show you what code we need okay so we need X 2 and we also need Y 2 so the code will need for this is pretty straightforward okay so we're going to need the center of the screen so we already know that's worth / - we'll need 2 plus that - the radius which we are in those are okay and we're going to need to times that by math dot costs okay and then in brackets we will also need the actual angle okay or the rotation that we're already getting here so I'm just going to delete that okay same goes for the X - we just do height / - okay which is the center of the screen again rotation okay times up by math dot sin this time okay and in brackets once again the angle okay so there we go we have that code now in theory that should go and work let's go and check out our that all know exactly what point of the actual graph it's on or actually on the circle so it's going to turn that on and you can see there as we're going we're going round and it's moving that line along the circle going around the only problem is that it's actually not it's off its off its number you can see here that this has got two rotations but it still hasn't even completed a circle over here now I know what's wrong with that is that because this is reading when it does a full rotation it gets to okay that's a full rotation for one however on a actual screen itself it goes all the way from zero degrees all the way to 360 degrees okay so we need to actually upper this number here because it's not making a full rotation now the calculation for that it's pretty simple all you need to do is go and take that rotation number and we're going to be going times it by six point two eight to make a complete circle okay so now if we go and spawn this in you should see that as that rotates we'll get a same rotation on our screen okay as you can see they're going around and goes all the way around the only problem though is when we started always starts here on the right which is not correct because it doesn't mean that it's on the right angle it starts in the screen facing that way hive our radar starts facing that way okay so we know that zero point so we know that six point two eight is the entire screen itself so what we're going to go and do is we're going to say that if we go back into our lua script just over here we're going to say that this line is incorrect it's actually ahead by a certain amount so we're going to take 0.28 and we're going to divide that by four to get four sections of these screens okay now the number that we're going to get out from that let's go and do the calculations quickly so we have six point two eight and we're going to divide that by four and we're going to get 1.57 okay so we know it's a head bar 1.57 on the angle so all we're going to do is we're going to take a minus one point five seven I'm going to do the same for the second one over here okay and let's go now and see if it's not at the center of our screen at the top okay so guys oh look at that it's at the top as this rotates now that's going to rotate and now perfectly in sync okay just a simple calculation to go and figure that part perfect so we now got that all set up Adam working okay so we've got our radar actually moving around the screen now if you wanted to add in some extra complex or extra detail onto this we decided that we want another lined trailing behind it okay so it almost creates like the sphere moving around now to do that what we're actually going to go and do is we're going to add a new line we're gonna say the color is also going to be a bit green however we're going to add some transparency onto it so we're going to say 50 is the transparency okay actually let's go and do one we do 150 is the transparency we're also going to go and use a triangle okay so you can see here we're going to go and grab and we're gonna do a filled one so a triangle filled okay so triangle fold is going to be from the center of the screen which is width divided by 2 and height divided by 2 and we're gonna go and take it all the way over to X 2 and X 1 and y 2 sorry ok so that's fine but we also wanted to go back probably about 5 degrees or 10 degrees backwards okay from where we are so what we can do is we can go and just say X 3 let's say Y 3 okay they're going to be the same as these so just copy and paste this it's changed us number 2 3 a change 3 3 and we're going to say that it's behind now how much behind you want it's up to you I'm going to go with maybe like another 20s make that 77 okay now in theory that should go and draw a trail behind our screen so let's go and spawn that in turn it on and there you go you can see we now have a trail behind our line that is going and picking actually going and drawing okay so it's just drawing and asked also a thing it's right behind that okay I said you can get a little complex with us you can add more make a bigger make it smaller it's really up to you okay now the next thing we want to do is we want the actual radar to go and pick up something on our screen okay so as soon as it detects something we wanted to go and draw a dot on our screen okay so this is the next cool thing so let's go and just make a little more space on our lua script here we're going to need to wait to take our on off block to when it's found something and convert that over to composite so we're going to go and use our composit right once again let's go and put ten channels or just on each channel one that's going to put ten channels on that and let's say that this is going to connect through there into our Luis grips and we're going to say this is going to be number two okay so that's going to be our second one so if it detects something it's going to send something on channel two so let's say T which is going to be target equals and waits two inputs starts to get full and we're going to do one okay perfect so that's going to be on one next thing is we want to draw a little dot on our screen if it's found something so to draw that little dot on screen we're going to say well if T then scream dot set color because we're going to have a red color if it's found something okay and we're going to do red to our to 5500 [Music] close that off and then we're also going to do a little circle but this time we're going to do a circle filled okay so circle filled perfect copy that paste that in so draw a circle okay filled at X Y and radius okay radius we're going to go with the one radius because we're on a smaller dot on our screen okay and X Y now x and y is going to position where the radar current is at the moment which is just over here so we're going to use x2 and y2 perfect so now if it detects something okay it will point an or drop a dot on the screen where we want it however we know that x2 and y2 is the edge of our screen okay that's what we know already we know it's the edge or and we don't want it at the edge of screen we want it somewhere in between depending on the distance now we'll come back to that in a couple minutes we'll just test to see if this works and if it finds something and actually draws something at the edge screen okay we've got an arrow that end okay we're missing an end here okay perfect let's go spawn that in let's go ahead and check it out let's see if it actually is working okay if it does it should draw a little line at the edge okay so if it find something now won't find anything except me or that fuel tank there so let's go and see as it goes round it should draw a little dots okay still hasn't finally so let's increase the radius here of our little dots it probably helps if we actually change that to two also because we had it on one which was incorrect so let's go and place that it's not a child to which we did set and now it should actually in theory go and work without increasing the distance so let's see if we get a little red dots yep there we go can you see the little red dot it picked up me and I picked up that fuel tank perfect so we got the little red dot on coming on the screen however now we want that little red dot to come up depending on what the distance is so if it's far out it's going to go to the edge if it's close to where the radar is we wanted at the center of the screen okay so we need a way of measuring that distance and that's why we have this little distance number coming in and that's actually going to be coming in from our radar itself okay where it's founded so to get our actual distance on the actual screen to come up what we're going to be doing is we're going to be taking the distance over here and we need a way to convert it because you know that our actual radius of our circle is only 32 so we're going to be doing is we're going to be taking that distance and we're going to be using a function block and we're going to be dividing it by 32 okay when I said that's number two okay so it's gonna be X divided by 32 and that's on channel 2 so let's come back into our lua script and let's say that our target angle night let's say target distance okay its inputs dots get number two okay perfect so TD equals that ah okay that's great and now we can come on to draw a circle okay and we can actually start configuring it a little bit different because it's gonna be a different position okay on where we want it at the screen and you can see here we can change it by using a radius so what we're going to do is we're going to copy all of this okay place it down here we're gonna say x4 and y4 is with done it up plus instead of using our we're going to use TD okay TD over there everything else we can leave it as it is yes fantastic and now we can change that our circle is going to be on x4 and it's going to be on y4 okay you can either use sorry you guys can either use the first radar point or the second radar point it's up to you there I'm using the second radar point okay and let's go and spawn this in now update it jump it in and now depending on the range it should draw in different places on the screen okay so let's go and watch it okay and you can see all it's drawing it all the center that's because we have a total range of 5,000 for this radar and the stuff it's for the testing that's probably within a couple meters okay so it's gonna always draw in the sense of the screen so we want a way to actually tell the system to change the maximum range that we can have not to do that what we're going to be doing is let's go and grab a small keypad okay place it in and we're going to tell a small keypad that let's say max distance is going to be twenty-five or fifty or hundred and so on and so forth so we need to add away here let's go let's put range okay number input perfect let's go that's okay we'll come back to that in a couple seconds this is going connect up our small keypad it's more keypad going in make sure it has a Christian does now we can go back to the lure and let's start working out okay so we know that our total range currently is 5000 so let's go and constant number and that's going to be 5,000 so that's our total maximum range this over here is going to be the range that we want so what we're going to be doing is we're going to be using once again another function block I'm going to say is the total range of 5,000 okay and then we have the range that we want so we're going to say total range which is X and we're going to go and divide that by Y which is the range that we want okay which is going to be like 500 200 100 and so on and so forth okay that's the thing - then I'll put an equation so for example if it's 5000 that's a maximum and the range we want to only 500 we're going to have an equation of 10 that's going to come out okay so what we want to go do now is we want to go and tell that this distance coming here is going to be x by this okay so once again let's go and grab a function block okay we're gonna say that this is going to be x by this and it's going to equal our new distance okay so x times [Music] by y is equal in our new distance okay so let's go and spawn that in or once again if we come over here and spawn that in turn the system on okay there we go let's say that our distance is now going to be let's go with 200 okay let's see now where it picks up everything on the screen okay you can see it kind of just came on there for a couple seconds and then went away but it is drawing it at different areas so you can see look I picked up that and picked up me really close to it if we increase or decrease the to 100 you should notice that I'll come there and then it will go okay and it came in for a split second okay now that's not really helpful because it doesn't actually tell us that it's something's there it's going away too quickly now we can't change that how we can do it is two ways first thing what we need to do is we need to tell that total system that on signals coming in and we needed to hold there for let's say two seconds okay now what we're going to be using is going to be using a capacitor for that okay so you can see we have our capacitor coming in there I'm gonna tell the system actually know it if it comes in it takes something it's going to sit on that screen for about two seconds okay which is fine let's go and spawn it and test it now I know something's going to be wrong with that but let's go and actually just have a look let's say 100 is our range that we want okay and look what happens okay it detects something but the problem is it's detecting as it's moving which we don't want we want that actually to hold and sit as soon as the text something we wanted to hold in a sit there for a couple seconds we don't want it to move back into the center of the screen okay now to do that we can come back and read a way to actually register memory to memorize the number of where the radar is and hold it there for let's say 2 seconds so we're going to be using is we aren't using a memory register for that okay we'll need to here let's start with one memory register just over here because we're going to remember where it is on the screen and the rotation oh and actually we will need another one because we all need to remember what the distance of that part is okay so we want to remember where the distances so it's going to grab that and we want to remember where the rotation is okay so we're going to go and grab those two things just over there so next thing is what we can go and do is we can go and say what if it detects something we wanted to hold it so we can set the memory now instead of setting it all the time we just need a pulse go pulse and we're gonna pulse it so when this is detected okay it's gonna pulse this on Kate up I found pulse it and it's going to lock in the two things which is going to be one the rotation and to the distance of where it is on the actual screen itself okay so it's gonna lock it there now we're going to go and take that in okay and we're going to say that let's go with our top one which is going to be our distance okay can actually override actual number two and then our position of their angle is going to go to position three why not okay however we also need a wave to tell it that it stops remembering that number four after five seconds how we do that is we use a not block okay so it says after those five seconds it goes and turns used to be reset okay straightforward the last thing we need to do is we need to go and code in number three so we'll come back into our lua script we say okay so the target angle okay or toddler found angle is going to be equal to three so that's just gonna replace this quickly angle and that's gotta be three okay and we're gonna say okay target angle that is going to go and come over here okay target angle target angle because that's the fix our line which is that our circle which is down there okay let's go ahead and click that let's go and spawn us in and see if it works now okay now in theory that should go and hold a position at one point it's gonna say our target distance is 100 okay let's turn the system on it's gonna go and find it theory it should hold that dot okay it found something which is really nice and close which is probably me okay okay and you can see it's holding that quite a few seconds it's going to move away here okay it's still finding something very close so it's going to change that to let's say 200 still very very close let's go and have another look there and see what's going on so let's go back into our microprocessor so let's have a look here and see why it's not picking up anything it seems like okay so we have target found when it something is found it's going into the capacitor it's then obviously holding that charge and sending out and on signal for let's go two seconds and then it's going into says actually not telling it to hold that which is wrong so this actually needs to go to push to toggle and then the push to toggle should go there that should then fix it in very so let's go and smaller and let's go and test it one more time so let's say our target distance is 100 meters let's go turn on I'm gonna get out the way and see if it detects that fuel tank there we go can you see it's holding that fuel tank now it ignored me because I'm was in that two seconds of when it's rotating around so you can see well it went and found that if we go and stand before that tank it should detect us yep there we go can you guys see it detected us now on the range we can go and drop this down let's go to 50 oops Kate didn't find anything it's got 50 meters let's see where I am close to the right there we are you can see there are I'm on the radar it picked me up first I think that's probably about 50 meters let's go and see what it's thinks okay didn't find that - just found me again let's go and increase it to 200 there we go and had found that which I'm guessing is is that yeah let's go and see that should be the yep it's over there increases 300 and that should go and move in closer yep there we go can you guys see it's going and detecting things so that's a fully functioning radar as I said you guys can get into a little more detail about that I think I've might do another tutorial and showing how to get multiple different different places so you can find me and I can find that and show it both on the radar obviously you can increase that time it shows on the screen to our little chosen screen it's really up to you you can increase the speed of this it's it's it it's really up to you if you want to increase the speed let's go and put it at 0.15 okay that radar should not move out of quite a quick speed so let's put it on a 100 it's going to turn it on you can see not rotating much quicker okay it found that once again so it's really up to you and as you you can move this around so let's say we move its facing that way you can see now look there it went and found that again it's gone a little bit out of the range of scope so that's put 150 and let's see that was the old position there's the new position so you can play around with this as much as you want but this is pretty much the very basics of how to get it to work I said you might want to try different radars it really is up to you but that's pretty much about basics of it so I think we'll go ahead and end todays video over there thank you very much for watching I hope you enjoyed it and found some entertaining and informative as always and all see you in the network [Music] [Applause] [Music] [Applause] [Music]
Info
Channel: MrNJersey
Views: 93,779
Rating: undefined out of 5
Keywords: Stormworks, update, news, major, next, island, map, area, snow, mountain, land, friday, improvements, thumbnail, screens, monitors, radio, camera, lua, code, script, laser, distance, shark, megalodon, attack, bug, electric, battery, winch, cable, fuel, rockets, space, space engineers, missile, composite, seat, new, speaker, mic
Id: cagLE3ZYelE
Channel Id: undefined
Length: 33min 48sec (2028 seconds)
Published: Sat Oct 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.