Unity 2018 - Game VFX - Laser Beam Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to tutorial number 24 of the series visual effects for gained and today we are going to see how to create lasers the lasers you are seeing are available nested for any my patron links are in description leave the package that comes with nine laser prefabs and shaders and a lot of Texas that will help you to customize them and since these lasers took several hours to do I will show you how you can get started and created subject simple and cool like this so let's say we can do this so first thing we want to do is to create an empty I'm going to rename it to laser test zero one and inside that empty let's create a line in effect so yeah lasers are basically line renders and we can turn off cast shadows receive shadows and dynamic occlusion we don't need that unless you want to create shadows from your laser anyway as you may notice we can assign a material which we will see in a moment let me first talk about positions a laser is composed of vectors which is this array of two and as you can see if I start increasing the Z value of the second element we are basically controlling the length of our laser use ball position will basically move our elements to their respective rod position and if we go to the respective parent of this laser and start copying the valves from X then from Y & Z which in the second element we will still use it as the maximum length of our laser you will see that now it's using the world position of the parent and we are going to use this in a few moments anyway now what really matters is the white the white can control how big our lives is coming to be and by the way yes you can add more positions as you can see you could control it in several ways like this but for the sake of this tutorial we are only going to use two positions next thing is this curve which is really useful let's add a key this basically controls the thickness so if I start decreasing the end of the curve we will have a phenol laser at the end as well now let's give it some color and this is a gradient which I'm going to use this one you can use anything you want of course and just for curiosity's sake hand cap-vert this will make the end of the laser round as you can see in wireframe it simply added three vertices but we don't really mean it so let's jump over to photoshop or to your image editing software of course where we can create a file with 500 by 500 and let's create a very simple texture just to show you a couple stuff about the line render and lasers basically I'm fighting the black brown to black and using this brush where I'm going to paint a white M shape something similar to this and we want the beginning and the end to be almost equal just like this now I'm gonna put some lighter fields in the middle here just like this and then with the erase tool I'm going to create these little depressions just to make it look more random now again with the brush we want to select a gray color and paint some gray areas yeah just like this now we can double click the layer and give it some outer glow let's crop this texture hide the black background and export to unity once in unity let's create a material and change the shader to particles additive assign the text in material and assign the material to the line renderer just like this and we can start seeing some cool stuff happening now let's control how much wide we want I'm going to set this to around 1.8 and now as you can see there is much apnic so we are going to create a very simple shader that will allow us to move this texture in the X or in the wire and I'm going to use shader forge but you can obviously use the new killer graph from unity the ideas are the same the concept is the same and by the way shader Forge is free now in the asset store so as soon as you open the shader Forge we can create a new shader and select particle additive just to get started alright cool so I'm going to change the sphere to a plane and turn off skybox just like this and let's assign the texture that we have created to our main texture of the shader and now as you can see we don't have any transparency we don't have the Alpha so outside the multiply node and plug-in the Alpha from the texture and out from the color and simply plug in these multiplied to the overall multiply and here we go we have transparency now to make our texture move in the wire in the X we are going to need the time node and then we are going to need two values one is for the expeed and the other is for the Y speed now let's select an append note and let's multiply these two values with time basically and now we basically need to add these with the new V coordinates so it can get mapped into geometry so let's create an ADD node and a new V coordinate node connect them like this and then we can pass this information to the UV input of our 2d texture so now let's press compile and nothing really happens because we need to insert a value in the X pit or in the Y speed and now we start to see the texture moving which is great now let's go back to unity and change the shader of our material to the shelter we have created I'm going to select the line render and down here we can control the speed we want and also control the color intensity of our laser as you can see that's looking great now just a little trick for you guys we can increase the X in tiling it will basically increase our texture amount in the X and it also gives a different look give it a try alright now let's go back to shader fudge to make a small improvement because as you may notice the beginning and the end of our laser have these are edges and we don't really want that and fix that we need to create the mask basically and we are going to use two texture 2d nodes one is for the mask frame basically for the ball texture and the other one is for when the texture is repeating and we want to add a little fade in and fade out from one texture to another all right so for the mask texture we are going to need the information that comes from this add node basically it needs to follow along the main texture and now the main texture needs to be multiplied with this mask just like this and nothing really happens because we need to add a texture to the mask I will show in a moment how to create it and as you can see now it fades in and fades out between the repetition of the main texture and this may be useful to you in case your texture doesn't loop too well in this case I'm also going to add the same texture to mask frame but you can use different masks and we can connect the RGB to this multiplier now for the texture we can open Photoshop or your image editing software create a file with 500 by 500 paste background to black create a new layer with control-shift-n and paint this layer with whites now we want to choose the selection tool select 50 pixels in the left and let's feather 10 pixels and press delete and we repeat this process for the other sides as well once we have done this we hide the black background and export this texture as a PNG to unity once in Ooty let's add the texture we created to mask frame and as you can see now we have a fade in and fade out at the beginning and in the end of our list you don't necessarily need to use the mask text like I said you can use it if you want now if we want to spice up our laser we can actually add a lot of effects in particle system to make this look even better and just to give you a few ideas let's create a particle system we name it to beam set the start speed to zero we don't need shape let's turn off that we can set the emission - - and the start life time can be random between 1 and 1.5 all right now let's increase the size between 3 and 6 or less and let's create a nice fade in and fade out the keys on top controls the opacity and we want to set this key in the middle like this all right nice and now let's use a curve in size of a lifetime like this one it's looking good let's move this beam to the beginning of our laser and now let's choose some color and I'm gonna go with some light blue and light aqua color or something like this and here's a quick and simple idea for you and now you may ask what if we want to use the laser without mouse and I'm glad you asked it because I'm going to show in a very simple script how you can do it so let's create a script call it simple laser and we did start function we can delete it what we need for this basic script is a public camera so we can basically calculate the Ray from the fire point of our laser to where our mouth is and speaking of fire point we need a public game object called fire point we also need a line renderer so we can say where the beginning and the end is of the laser beam and the maximum length that we want the laser to F and for the sake of this tutorial everything is going to happen in the update function and the first thing we want to do is say that our line render we're going to set the position of the vertex zero the element zero to our fire point position just like this which will allow the laser to follow the fire point and let's just see how this is affecting the laser let's go over to the inspector and assign the camera the fire point is going to beat the laser itself and the line Rainer and a maximum length of 80 should be enough now if you press play you will see that blazer is kind of messed up and what's happening is that sis lace is not using world face the fire point is going to be messed up because it's using local space and as soon as you turn it on the laser goes back to its supposed to be and once we get out of play mode what we need to do is do what we have done before which is copy the values from the parent of the lights and turn on world space just like this now as you can see if we move around the fire point of the laser is always going to be applied it thanks to that line of code that we have put in the update let's add a few more things so in order to know where the mouse is we are going to need a ray cast it and we are also going to need the mouse position like this and now we need to convert that mouse position which is just a screen point will it convert it to a ray just like this and now we do a simple test if the ray cast which goes from the ramos dot origin to the ramos direction and we output a variable called hit and if that hit hits something then our laser is going to be placed in that position in other words we are simply shooting a laser from an origin to a destination and see if it's something if it's going to hit something then the end point of our laser it's going to be place it in that position and now we see if that hits something so we use hit Collider and if it hits something we want to set the element one of our line render to that hit point which is a vector now let's press play just to see how this is working and as you can see the laser follows our mouse because the array that we are shooting he is hitting something but as soon as it doesn't eat nothing for instance if we point to the sky the laser stays in the last position and to fix that we say that if the Ray that we have shoot doesn't eat nothing we want to create the varial position that will hold a certain point with a maximum length of our array Mouse and once we have that position we can set the position of the element number one to that variable now let's press play just see how this is working and it works it's looking great and that's it guys that's very basic idea of a laser you guys can do a lot of things you guys can create new textures can improve the shader a lot the shader can do a bunch of things and obviously with the script you guys can give it some cool tweaks around I mean it's up to you guys I hope you have enjoyed it and if you liked it please subscribe leave a like and if you can please support my patreon page you can download a bunch of effects I want to say a special thank you to all the patrons that have supported me in the last month you guys Rock you guys are awesome really thank you and thanks for watching I hope to see you in the next video [Music]
Info
Channel: Gabriel Aguiar Prod.
Views: 61,789
Rating: undefined out of 5
Keywords: unity tutorial, unity special effects, game effects, unity particle system, effects for games, vfx for games, unity game effect, unity vfx, spell effect, unity effect, magic effects, vfx, unity bolt, unity ray, unity laser, unity laser beam, unity beam effect, unity laser gun, unique lasers, unity ray gun, laser, laser gun, unity line renderer, unity laser tutorial, unity line renderer laser, unity laser beam tutorial, unity shader, unity follow mouse, unity mouse look
Id: YbWYc3W43EI
Channel Id: undefined
Length: 15min 0sec (900 seconds)
Published: Sun Jul 01 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.