Unity VFX Graph - Ground Slash Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
shout out to unity for sponsoring this video they are amazing and once again my patrons voted and we are going to see something crazy which is how to create a ground slash the idea is that this pierces to the ground opening up the ground with a slash and the cool thing is that this will adapt to any terrain to any ground below it cool right this is a very complex technique but i tried my best to explain you the basis so i hope you enjoy it and by the way this is all available my patreon page you get access to this project and many many others that you can use in your games plus you keep the channel running links below and our sponsor today is unity they have some awesome sales in the unity asset store and it's that time of the year where you can acquire some aaa assets for your games or for your projects such as these ones that you are seeing i think it's a great way to improve the workflow of your game and to have a better result when developing in such a complex industry so make sure to check that out i left some links below you can also use this code right here to have an extra 10 percent off of your next purchase so make sure to use it when you are checking out so as you guys can see there's quite a few things going on we have a mesh we have some code so this properly follows the terrain below and i'm going to show you pretty much all the elements you need to create this effect so let's start by creating the mesh and for that part i'm going to use blender 3.0 by the way so let's start by selecting everything with a and pressing delete so we have a clean scene we want to press shift a to add a busy curve i'm going to press 7 in the numpad so we go to the top view and i'm going to rotate it minus 90 degrees in the z axis and then we can press tab to enter in edit mode and i'm going to select this handle right here and all we got to do is push it more or less around here as you can see we have kind of a slash shape if you go right here to the bezier tab in the geometry drop down menu we can extrude an amount of 0.3 more or less that's enough and that's when we start seeing something let's go to object mode and from here we can convert this to a mesh with alt c and by pressing tab we can go to edit mode and with ctrl r we can add an edge loop right in the middle press escape so it stays in place while holding shift and alt i'm going to select this vertice and i'm going to go again to the top view with 7 in the numpad and push it with g locked in the x axis more or less this amount as you can see we have some thickness right now i'm going to scale this down with s and lock it in the z we don't need this to be so thick and then we can take care of the uvs by creating a new window drag this corner down here on the left and on the top left corner we can go ahead and select uv editor and if we press on this little icon with two arrows we can now select this vertices hub here with b and in the right window we can see which vertices we have selected and in this case it means we need to rotate this select everything in the uv editor and rotate it minus 90 degrees so basically these vertices are on the left and if we select these vertices on the right as you can see we have the bottom edge loop and we want to go ahead and in the uv drop down when you turn on constraint to image bounds this will allow us to push all of this vertex with g lock it in the x push it all the way to the left until it overlaps with the other vertices and since these vertices on the mid represent the front of our slash we can push this all the way to the right just like this this way we can create a gradient texture and the front of the slash will be brighter uvs are extremely important to map a texture properly now if you want you can go ahead and shape a little bit this until it looks a little bit better in my case i'm going to push this vertice to the left so it becomes thinner at the top and a little bit thicker towards the bottom oh and by the way these two vertices right here you can scale them down in the z-axis you can press 0 and then enter until they are overlapped i think it will look a little bit nicer okay so once you have a shape that you like and that you are pleased with we can go ahead and let me just get out of see true mode by pressing z and with spacebar i'm going to go ahead and search for shades mood you can find it up here as well in the object drop down menu and this will make it look a little bit nicer from here we can export this in the file drop down menu as an fbx make sure you rename it and up here you turn on selected objects so you export only the slash from there if we go back to our unity project and this project was created with unity 2021.2.7 in the universal render pipeline all we got to do now is select the mesh and in scale factor let's increase it to 100 because blender by default exports this in a really small size you can press apply down here and to build this effect we are going to need an empty game object so let's go ahead and create one make sure you reset the transform and then in one of your folders with right click you can create a visual effect graph rename it and parent this to the empty we just created just make sure you reset the transform of this vfx graph and then you can press the edit button to open this window you can dock it wherever you want for the slash we simply need one particle each time right so we can use a single burst up here in the spawn area with a count of one we want this to move but via script so we don't need the set velocity block let's just say the lifetime is 3 seconds for now and down here what really matters is that we change the output particle quad to output particle mesh let's delete the other one and in here we can assign the slash we created okay so from here as you can see first thing you will notice is that this is super small and that's because we need a set size down here with output particle mesh we can say it's one okay so we got something we just need to rotate this properly up here in initialize part we can use a set angle which is 90 for the y and for the z and now this will face properly the z axis what's happening here is that we cannot see the inside of the mesh let me just increase the lifetime of this to 10 seconds okay so how do we fix this well it's super simple if we select the output particle mesh down here in the inspector in the call mode instead of default we can turn it off and now unity will render the front and back faces of this mesh cool another problem that's happening right now is that we kind of need to adjust the pivot we simply need to use a set pivot and say the x is around minus 0.8 minus one that's okay as long as it is above ground and the pivot of this object is touching the ground so as you can see it's facing the forward axis the blue axis that's exactly what we need you can also turn on soft particles by the way which means that if it touches geometry it will fade a little bit the mesh and let's do a few more things with this before we create a texture you could also create a shader if you go watch some of my videos you will probably be able to create a nice shader for this so with the set size over life we can control how this slash is animated we first need to say the composition is multiply otherwise it will overwrite any previous value we can use this curve but the first key let's say it's a little bit above 0.5 around 0.5 okay and let's go ahead and say the lifetime is not random because 10 seconds is way too much and 2 seconds is enough by the way if you don't see any changes whenever you are adjusting these values make sure to press compile up here and it will update your vfx graph so as you can see it grows a little bit and this will add a nice touch down the road okay so another thing we can do is use the set scale you can adjust the scale of the slash however you want what matters is that we use a set color so we can choose for example an orange and increase the intensity as well so yeah the texture is horrible this one so let's create a new one i'm going to use krita because it's free the idea is to create a new file a square file in this case i'm using 2048 by 2048 which is way too much anyway we are going to need a gradient so let's click up here and select this first created it's really important it goes from foreground to transparent because if you press edit now we can say that the color is going to be white of the first key and yeah let's select color and the opacity is zero but for the last key the opacity is 100 and the color is white and now we simply need to select the gradient tool and click and alt from left to right so it creates this nice gradient we can add the background and then export this as a png to our unity project now if we go back to unity you can select the texture and turn on alpha is transparency and then press apply and now in vfx graph in the main text we can assign the text we just created and that's it that's the simplest way to add a nice touch to this slash oh and if you have this problem right here and see these artifacts this means you need to go to your texture and say that the wrap mode is clamp and then press apply and they will go away okay so nice this is looking like something we can work with oh and to fade this out we can use a set color of a life by the way and for the gradient we simply need to make sure that it goes from white to black and the last key is transparent just like this and let's not forget to set the composition to multiply as well as the alpha composition and here we go it fades out towards the end really cool now let's see how we can leave a trail on the ground with the decal and for that we can start with the simple particle system but we only want this to emit whenever this object moves fortunately we have the spawn over distance at least in this version ut2021 and for the position we need to change the space there's literally a block that does it and we can say the target space is world and now every time we move this object we emit particles that's great that's super useful let's just set the rate per unit to four that's enough and well we don't need velocity and if we want this to actually leave a trail we need to set the wall particle system to world we can click here but if you try to move it the particles will be in the origin of the world and this is it's an easy fix we simply need a set position make sure it's l in here instead of w and now ta-da every time we move this we leave a trail of particles great let's take care of the aspect by completely removing this particle quad because we want a forward decal by the way vehicles are really a really basic in vfx graph at least for now they are going to have great improvements and for the simplicity sake of this tutorial we are going to use the default part that comes with unity you can control the size with the set size we can actually make sure it's random by the way between something like 1.75 and 2 and set the color to black this is the black decal we simply need to fade this out with the set color of a life degraded it's the same as the previous one it fades towards the end but if you try to move this it's very strange what's happening here is that we need to rotate each particle 90 degrees in the x and now it will be parallel to the ground oh and let's not forget to set the color of life the composition to multiply great from here we can actually copy this output particle for an orange decal so it looks like it's burning the ground basically we can decrease the size to something like 0.75 and 1.3 and the color you can choose a orange color increase the intensity it will look nice and now here we go we have an orange trail in the ground good let's see how we can use this in terms of code just so you can have an idea i have in my scene a camera and to this camera i've attached a character controller you can add down here in components and the first person control script well basically you can copy it this is all over the web it's simply to move a character in a first person perspective another thing important for you is the ground slash shooter another script attached here so we can shoot projectiles in the first person perspective this script is adapted from this tutorial that i made a while back basically the idea here is we check if we have press the fire button in this case the left mouse button we call the shoot projectile function which will shoot array from the center of the camera towards infinite we get a point 1000 units in that ray forward and we instantiate the projectile basically we instantiate the ground slash in that ground slash we have a ground script which i'm going to show you in a moment and it's very important that we rotate this to the destination as you can see we only rotate in the y-axis the x and z-axis do not move and then we add velocity to the rigid body we multiply the forward axis which is the blue axis by a certain speed from the ground slash so that's how we shoot the ground slash in the ground slash we have the script and the rigid body so let's add one to our ground slash let's add a rigid body you can disable the gravity by the way and then we can create a new script call it ground slash in my case i've already done it in here we have a speed a slow down rate so it stops a detecting distance so it detects the ground it's a ray shooting to the ground and a destroy delay then we get the rigid body and a boolean to know if it has stopped moving as soon as this is instantiated we set the y value to zero of the position so it snaps to the ground then we get the rigid body and we call a core routine and slow down core routine so it slows down the ground slash basically we lurp the velocity until it reaches zero what's also super important is in the fixed update if it doesn't stop then we keep on shooting array from this distance by the way perpendicular to the ground and if it eats something we set the y position of the ground slash to that specific heat point otherwise we set it to zero in my scenario it works well but as soon as it detects a collider it will snap to that collider and it will follow the geometry of the ground which is super nice so let's see this in action once you have all of those scripts in my case i'm going to assign to the ground shooter the camera and the projector so yeah we need to create the prefab out of the ground slash we created and then assign it to the projectile of the ground shooter script assign the firepoint which is basically an empty game object and once you test this out you are shooting projectiles like crazy this is only happening because if we go to our prefab the ground slash the speed is way too high 14 is enough slow down rate should be faster like 0.1 and for the detecting distance you can set it to 3 and not 0.15 and once you test it out oh yeah don't forget to turn off use gravity in the rigid body okay so yeah as you can see now it's very interesting what's happening here it's following the ground i mean you can do a bunch of things with this we are going to see but i can only show you the most important parts like for example let's see how we can add some debris to this so if you go back to your blender file you can go to edit and in preference in add-ons you can search for cell fracture turn it on and then we need to add the cube with shift a and with spacebar i'm gonna go with cell fracture which you can find in objects quick effects this panel shows up and we can increase the source limit above 10 recursive we can set it to 1 and it's important that we set the noise to 1 and then we can press ok and we get a fractured cube which means now you can select one or two debris from here and delete everything else once you have these two debris what's important is that you select them and you press ctrl a to apply the rotation and scale from here now you can select both of these debris go to file and index part select fbx and export this to your unity project turn on selected objects don't forget about it otherwise you will export the slash as well okay and now back in unity we can say that the breeze the scale factor is 100 we can start by copying the black and orange decal the wall particle system we can remove the two output particle decals and since we want a mesh we can use the output particle mesh and by the way in this new version you can control how many meshes you want to use you want to output i'm going to increase it to 2 and assign the debris we created at this point you could create a nice texture so it matches your ground or wherever you are using this in my case i'm simply going to set this iso pack and remove the main texture none and for example say the color is random between a dark gray and a light gray so basically it matches the ground i have we can also control the set size make it random between 0.1 and 0.66 towards the end of the lifetime of this debris we want this to disappear so we can use the set size of a life and we can use this curve push the first key to more or less around 0.504 so it shrinks towards the end okay if we move this we get something already but as you can see we need to add randomness and motion we can take care of that up here in the set angle we can say it's random between 360 and -360 in all of the axis and the simple set velocity will do the trick for the motion we can say it's random between 2 in the x and z and minus 2 for the maximum of the x and z and for the y we can say 0.5 and 3. so it adds force upwards and the strange phenomena happens if you move this around we are missing gravity right so let's add it to the update particle if we move it you will notice that they fall through the ground so we need to tell vfx graph that this is going to collide with a plane collisions in vfx graph are simple for now in here we want to say the bounce is 0.2 and the friction 0.8 so it stops moving as you can see it's looking very nice we can increase up here the rate per unit to 15 and increase the capacity to 250 oh and last thing we need to set the size of our life to multiply the composition all right and we are ready to test this out so as you can see every time we fire these up we are piercing the ground and leaving some debris a nice orange trail and we can do many things with this that's exactly what i did i added a few more elements i had these trails by the way which i used a tutorial that i made recently which is the stylized trail and it's quite useful and you can add particles you can add fire from this tutorial as well that i created stylized fire it's really up to you you have the basis now and from there you can improve this this entire project is available on my patreon page and by supporting me you allow me to keep on creating free tutorials for everyone and it would be super much appreciated a big thank you goes to each patron for supporting me and as usual a quick shout out to the top tier patrons which are elac frost bradford aaron krubydubedu daniel adcock david dhaka david maid lars derek benson donald thompson edward shai eriksson talau eric edson ft92 goblin black leonardo farage little tsai maxim mograph tech nat sims its radioactive bullfrog revenant game stefan zarkov very zuta and inglewood ass your sport is very much appreciated guys you keep the channel going and i hope you have enjoyed this video and i hope to see you in the next video thanks bye [Music] you
Info
Channel: Gabriel Aguiar Prod.
Views: 339,129
Rating: undefined out of 5
Keywords: Unity tutorial, vfx, vfx graph, vfx graph tutorial, unity, visual effect graph, unity visual effect graph, unity vfx graph, unity visual effect, tutorial, shader, shader graph, unity shader graph, unity shader, fx, graph, visual effect graph unity, slash, unity slash, slash tutorial, unity ground slash, slash effect, unity decal, unity fire, fire, unity debris, vfx graph slash, vfx graph ground slash, ground slash, unity tutorial, slash ray, fire ray, ray, unity ray, raycast, Fire
Id: qh3TEYUN6cA
Channel Id: undefined
Length: 23min 14sec (1394 seconds)
Published: Tue Dec 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.