Let's Build the RPG! - 58 – Unreal Engine 5 Niagara Fluids 2D Interactive Water

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this episode we're setting up two D Niagara fluids to be completely interactable with our player character [Music] hey guys welcome to today's episode and last episode it was all about making ue5 water what I like to think of as landscape water interactable with gameplay but the problem is we have areas of our game that are not directly tied to a landscape like this cave here and we need to have water in those areas too and it wouldn't make sense to have water be interactable in the ocean or Rivers but not indoors so we got to use the Niagara fluids plug-in and it's important to note that the Niagara fluids plugin is still in beta I've noticed some lighting issues some issues with the material itself but it still exceeds that b plus bar that I'm always trying to set with this series and I know Unreal Engine will be improving this in the future so I'm not too worried I think we're headed in the right direction in terms of integrating interactive water with the game that we're making we're actually going to start with 3D Niagara fluids this episode because it's much easier to get up and running interacting with gameplay but the problem with gameplay interaction with 3D fluids is in one word performance 3D fluids could work for cinematics but it's not going to work for actual gameplay so the majority of this episode is going to be focused on 2D Niagara Water in order to get that completely interactable with our player and to be honest I think it looks better than the 3D Sim but it could just be me and to finish out the effect next episode we're going to create an underwater pose process effect that will tie right to it so here are the key concepts for today this is the second episode in the series that we're using blueprint interfaces but I think today this episode is the ideal case for it because we have a series of actors it could be our character it could be something thrown like a fireball could be a flamethrower could be a rock something gets pushed into the water and we don't know what that something is and in any case where we don't know what actor is going to be interacting with something the best way to communicate between blueprints between actors is with a blueprint interface so let's get to it alright so to start the episode today just make sure you get the Niagara fluids plug-in enabled and if you're following along with this series you should already have it enabled back in episode 23 we did the Torchlight effect from Niagara fluids so you just search for Niagara fluids one word this one right here if it's not already enabled then enable it and restart the engine and then we've got to navigate back to the cave that we started two episodes ago and back in episode 56 that episode I said create a small space in your cave that's going to contain our water and I've got something like this but whatever size you want that's totally fine and because our caves underneath our landscape that's why we have to use the Niagara fluid Sim so that's what we're going to do so under content drawer and under content I'm going to go into the Niagara folder under environmental effects we're going to create a new folder here and I'm going to title this Indoor Water double click to go into that and then we're going to right click create a new Niagara system and we have to create a new system from a template or behavior example next and we see all the different examples here from Niagara fluids and what we're going to choose to start is 3D liquid specifically we're going to choose the grid 3D flip pool and then finish and I'm going to name this 3D Niagara Water all right first things first let's just pull it into the scene get it up and running and there's nothing what's going on here why isn't it showing up and it took me a while to troubleshoot this but the reason it's not showing up is because it's dependent on the landscape by default and because right now we're underneath the landscape nothing's going to show so we have to go into our Niagara system here I'm going to expand this and I'll pause the fluid Sim and we have to select the fluid control emitter our main emitter here then I'm going to select collisions over here on the right in emitter summary in this checkbox here it says use landscape collisions no let's uncheck that and once you do that and it took like 10 seconds to actually process that for me and I've got a pretty good machine and it shows you how performance intensive this system really is but once you do that we can exit out of this and voila then we've got our water so I can right click right next to it and say play from here and we can just run right into our water and then we have a fluid simulation right but nothing's happening when I run into it and the reason is we have to tell the fluid simulation that our player character here is a collider so on the fluid simulation itself if you expand under Collide meshes here and actor tags you see a tag of collider here and so any actor in your scene that you add a tag of collider will then be able to collide with this Niagara system so we're going to go back to our contents for our back to content core I'm going to open up my third person character here and on main actor itself if I search for tag on the details panel then we have our tags here and we added this player tag for AI purposes a few episodes ago I think it was intro to AI but now we're going to add a second tag and the second tag has to be verbatim exactly what's listed here so we can just copy and paste collider and then go back over to a third person character paste that in and then compile and save and then right click anywhere next to the fluid say play from here and we should be able to yep run into our fluid and Collide but there are a few problems with this so let me show you a few to start so if I try to move this down yeah it looks like it's moving but then I play from here and it's floating back up in the air again so I find that these are particularly annoying to place basically the way to do it is to set it to a particular level in your scene and then change the water height here to however high or however low you need it to be but that's not even the main problem the placement's just an annoyance but let me show you my FPS so with this in our scene if I look at my frames per second I'm at 60 FPS 50 actually now given I'm recording right now but like I said I have a really good machine and we have zero foliage currently in this scene this is not going to work for gameplay now if I delete this out of our scene we're up to 100 FPS so this 3d water effect I am not going to use it except maybe for cinematics but even then I'm not convinced I need it so then the question becomes what do we do instead and so what we're going to do is we're going to use 2D Niagara Water instead of 3D and the performance is way better and to be honest I actually thought it looked better so that's what we're going to do so in the same folder we were just in the indoor water folder I'm going to right click here we're going to do a new Niagara system new system from template or behavior example scroll down all all the way to the bottom we're going to choose one of these shallow Waters and I played with both of these but ultimately I found this one easier to interact with and I'll explain why so we're going to choose grid 2D SW particle collisions and I'm going to name this shallow water with Collision 2D and so we'll go into that and if you want to see this what you can do is just hold left click and kind of tilt the camera a little bit and then you can see what this is doing so we have an emitter here the shallow water Collision particles emitter that this is the ball this is the particle and then the emitter over on the right is the actual water surface so to start let's just get this up and running in our world and I'll explain the things that we're changing within the system so if you select the set particles position velocity all this right here one thing I found is that this entire grid is 20 meters by 20 meters so it goes 10 meters in any given Direction in the center is zero zero zero the particle's position and so for example if you come up here to the right and you search for a random range vector and what we can do is we can specify all right negative 1000 negative one thousand zero and the maximum is one thousand one 1000 and also zero and then that particle is going to spawn anywhere in the vicinity the one last thing we got to do to change the position of the particle is this set particle's position here so instead of this particle's position where we're getting the engine owner position I think this is the position of the simulation itself instead of that we need to get where our particle is and I'm going to keep the B here because the B is determining how that particle is changing across time but for the a what I'm going to do is erase this and instead what we're going to use is under particle attributes over here on the left we're just going to get our particles positioned drag that in and then the other thing we have to do here is make sure the period is 8 and the scale is eight so to back up for a moment the way this particle is moving through the water is it's taking the particle's position at any given moment in time and then it's adding something to it because we have this add Vector here this is our particle's current position B is what's being added to that position and that's happening every single tick because it's under particle update in cosine it's basically a wave function it's oscillating it's going up and down and up and down that's why our particle is going back and forth and I just played with the period in scale until I got this to where I wanted it to be but what this is going to do so what we just set combined with this right here negative 1000 negative one thousand one thousand one thousand is any particles that we spawn here are going to be at random somewhere on the grid and so under spawn burst instantaneous if I crank this up to like three particles they're going to be all over the place so if I hit play yeah there we go so let's save this for now and here's the other cool thing I want to show you so go into your world and take this system and drag it into your world and you should see those three balls somewhere along the edge but you're not going to see them in the water and why is that like why are they all the way over there so what I figured out is going on is this particle is positioned here when we set the location of the particles it's not relative location it's not the local position within the system what it is is its World location so that negative 1000 negative one thousand one thousand one thousand that is World position that's like literally where they are in the world because our system is all the way out here whereas if I move our system to 0 is 0 then our system is over there and you might think that's kind of weird but when I saw it was working that way it was just light bulb boom because what that means is we could pass in whatever Collision is occurring in World position and that's going to affect the water at that world position and initially what I was thinking is okay for every type of collision we need a different kind of particles so we need to have all these different emitters one for footsteps and actually two for footsteps one for left foot one for right foot and one for our flame thrower etc etc but then after testing this I was able to get everything working with a single emitter just a few particles it was beautiful so we're going to keep this really simple and I think it'll work just the way you need it to but if you come up with better ways of doing this please post by all means in the comments below alright so where do we start with this so I'm going to exit out of this I'm going to delete this out of our world we won't need that and instead what we're going to do is we're going to create a brand new blueprint so under content blueprints environmental right click blueprint class parent class is going to be actor and we're going to call this shallow interact Active water body and we'll go into that and we'll go over to the event graph we won't need event act or begin overlap or event tick and we'll add a component so I'm going to add a Niagara system component Niagara particle system component and I'm going to name it water surface underscore NS and we can assign our Niagara system to that so if I search for shallow water with Collision 2D and with this blueprint we're going to start out with the simplest possible example of getting the interaction working which is we're just going to trigger a drop in the middle of the Niagara system meaning the ripples are going to go outward and we can specify how often we want that to trigger So to that end we're going to create two variables so our first one is water drop question mark that's going to be a Boolean we're going to make this instance editable and exposed on spawn and the second variable is going to be the rate of water drop and that's going to be a float so change that over to float also instance editable Exposed on spawn because what I'm thinking with this blueprint is eventually this is going to be a ubiquitous blueprint we can use anywhere in our world so we're going to be able to use it in places where we want like a waterfall coming down into the water and triggering little collisions where it hits but also places where it's just a Still Standing pool of water and we could turn off the water drop feature but it still interacts with our player in other characters so that's the vision of this blueprint it's probably going to grow and change a lot over the course of this series but we're starting it right here alright so here's what we're going to do on event begin play we are going to assess okay it's water drop activated so is this true so from that we're going to Branch hook that up to event begin play because if this is true then we are going to set timer by event but in order to do that we need to create a new event so I'm going to come down here search for custom event add custom event and we're going to call it spawn water drop particle and we'll connect up our event here down there because every time this is triggered then it's going to spawn a particle now the question is how often do we want to trigger that and for that we're going to get our rate of water drop and all I'm going to do here is I'm going to divide it by 60 actually the other way around so I'm going to take 60 and we are going to divide that by our rate of water drop connect this up here and the reason for that is this is time in in seconds so if the rate of water drop is 60 then it's going to do this one per second and last but not least select the looping and so now the question becomes okay when we trigger this event to spawn a water drop particle what do we want to have happen in the Niagara system and so for that we got to go back into our Niagara system so go to our water surface NS here double click here so the first thing is we're going to change a couple of things in the system to get it up and running so the particle radius here instead of this being a hundred which is a very large particle I'm going to reduce that down to 20. and initially I tried reducing this even more because you got to think of like a water drop hitting the water it's really small but I found that setting this to anything less than 20 sometimes the collisions didn't occur because sometimes it was above the water plane so you have to set it to a sufficiently large particle such that you always get the effect that you're looking for so then we're going to add three user exposed parameters here we're going to expand this hit plus sign make new and under common the first one is going to be a float this is going to be called spawn rate it's exactly what it sounds like then plus sign again make new common this is going to be spawn location which is a vector spawn location station and then plus sign another one under common Bool this is going to be called kill particle so the way I got this working is I spawned the particle for just a fraction of a second like 0.2 seconds and then after the 0.2 seconds I killed the particle and just in that 0.2 seconds the particle moves it creates a ripple and then there's an effect so what we're going to do under particle update I'll hit plus sign here and I'll search for kill particle let's kill particles and then I'm going to take our kill particle Boolean and drag that over connect it up because when we set that in our blueprint then it's going to kill the particles and then under a mirror update here instead of spawning burst instantaneous I'm going to hit plus sign we're going to add a spawn rate node we're going to uncheck spawn burst instantaneous and for our spawn rate we're going to attach our spawn rate right here and last but not least under particle spawn where we set all these things we're going to take our spawn location here and set our particle's position so we're setting our particles position on spawn but you heard me say we need to make the particle move a little bit because what I found is that if we just spawn the particle and it doesn't move at all before we kill the particle it doesn't actually register on the surface the particle has to move in order to create the ripples so in order to do that what we're going to do is under set particle's position here I'm going to get rid of the cosine here so I could just hit the arrow next to the b blank this out and I'm just going to set this to a very very small value so it doesn't even look like it's moving but it's moving so why 0.1 and that's going to be just enough to get the ripple effect that we want when a particle actually hits the water we don't want this to be too high because when the particle hits the water then suddenly it's going to Ripple in one particular direction which doesn't make a lot of sense unless you got a projectile of some sort that's hitting the water and that's what we're going to do with the flamethrower so we are all set with our Niagara system we can compile and save this and back over to our blueprint so from here I'm going to get a reference to our water surface Niagara system and from here we're going to set a pool parameter under particle system connect this up and the first thing we're going to do is we're going to tell it okay when you spawn a water drop particle set the variable kill particle set that to false because we don't want it to be killing the particle and then I'm going to copy that water surface NS paste it over here because we also need to set float parameter water and the float parameter is our spawn rate that we just set up so parameter name spawn rate and then for our spawn rate I'm just going to hook up our rate of water drop so get and connect this up here and in reality we only need a single particle in order to get the effect that we want but what I found is that this rate of water drop is important to tie up here because the particles are going to be continuously spawning but in order for those particles to spawn at the rate of water drop we need to tie those two things together I tried experimenting with just a single particle that was always there and just moving it to the appropriate location but the problem is when you teleport the particle to a location then it causes Ripples and all sorts of things I figured you know what we're just going to spawn particles continuously it's not that performance intensive and this way we can kill the particles very quickly in and out of effects so then I'm going to come over here to the right we're going to get another reference to our water surface because we have to set our last parameter and that is a vector parameter so set Vector parameter under particle system here connect this up that's parameter name spawn location and make sure you get these verbatim or else they're not going to work so they have to match the names here verbate and so for this you heard me say to start we want the particles to spawn right in the middle of it we just want to get this thing up and running and then we can randomize where it's going to spawn later on so I'm just going to get our water surface Niagara system and we can get the world location and that's going to be the very center of our Niagara system and then connect this up and the reason this works is as you saw before the particles are being set based on world location rather than where they are in the system itself so the last thing we're going to do this is kind of weird but it worked just fine for me what I'm going to do is delay until next tick because we're going to set the particle to live for one tick we're going to move it a little bit and then we're going to destroy the particle and the way we can destroy the particles I'm just going to get a reference to that same set pool parameter paste that over here and say kill particle connect this up all right let's compile and save and now we can drag this into the world and it's not going to work see if you could figure out what we forgot under the three dots here just make sure you've got simulate checked just like this and then hit play and nothing happens so Y is nothing happening so what we forgot to do is we've got to set variables for water drop and rate of water drop so those are the two variables that we Exposed on spawn so that we can set them when we drag that into the world so I'm going to say water drop yes and let's do 60 a minute because that's what this is It's how many water drops per minute so now we can hit play and in a second boom there we go and there are water drops and they're right in the middle because we didn't randomize the location at all we just got the center of that Niagara system passed in the world position now there's something weird going on with the water here that I found and if you get very close to the base of the water you can see it so the water level actually continuously drops so it started up here and it's dropping and it's dropping and it's dropping it's almost like there's a drain at the bottom of the Niagara system sucking all the water in and you know I look for all sorts of settings on the Niagara system itself to prevent this water from draining and I couldn't find anything but I did ultimately find the source of this and a way to stop it but it has a consequence that I don't like so let me show you that but I could use your help in the comments below if you know an easier way of stopping this water from continuously dropping down all right so let's stop simulating we'll go back to our Niagara system and what we have to do is we have to go into the material itself into the water material so I'm going to select our mesh up here and then under mesh rendering we have to select under override materials index zero this water material instance so go into that and this water material instance for the Niagara system it's using our water material here I should also mention by the way that you can change the watercolor here if you want to make it darker or lighter you could change the foam the scattering so feel free to play with that but let's go into the parent material here so what's actually causing the water level to continuously drop like that is this world position offset here this transform Vector node over there and the way I stop this working is I literally just broke this connection hold alt click and then apply and then save your material and that's not ideal because it leaves a residual effect which I do not like and so like I said if anyone has a better way of solving this problem please let me know but now if I watch it simulate let's just watch the water level let me show you what happens here so the water no longer drops but we get this weird kind of residual effect that develops along the edges it's not the end of the world I mean it doesn't look that bad but it doesn't look great so asking for help a third time if you know how to resolve that and if I ask three times that means I really mean it so please post in the comments below so now it's on the character interaction with this water and we're going to start pretty much the same way as everything else with footstep effects so what I'm going to do is well first thing let's close out of our water material instance here we won't need that and I'm going to minimize this and go back to our content drawer and the way we're going to set up the communication between our character or really anything in the game and this blueprint and this water right here is we're going to use what's called a blueprint interface now if you're following this series we've already implemented one of these it was back in the gameplay ability pickup episode I think that was episode 33 but the reason that we're going to use a blueprint interface is that in any situation where you don't know the actor that's actually interacting with a blueprint with another actor then an interface is the ideal means of communication because if we know the actor that's hitting something thing like we always know okay it's hitting the water actor and it's always our player then we can cast that's just fine but if it could be a rock if it could be a fireball if it could be something totally random that's hitting that actor then we got to use an interface so I'm going to go back to our content drawer and under blueprint interfaces we're going to create a brand new one so right click under blueprints we're going to select blueprint interface and I'm going to call this blueprint interface Niagara interaction and we'll go into that in our first function here in the top right I'm going to call this footstep Niagara Water and for our footsteps we only need two inputs here so we're going to hit plus sign with input and the first one is going to be our hit location and this is going to be a vector so where is that footstep occurring and the second one is going to be a hit size and we probably don't actually need this one but I'm going to put it in there because we're going to need it for things like the Fireball and the flamethrower and I suppose if we have a character with giant feet then it is going to matter so we'll compile and save this and the next thing we're going to need to have up and running is our animation blueprint so for that I'll go back to my core folder ABP third person character in and back over to our event graph because what we're going to have to check or what we're going to have to manipulate is our footstep line Traces by profile left and right and the reason we're going to have to manipulate these is this is what we set up all the way back in episode 20 I think in order to check are we hitting water and if so what is the depth of that water so let's go into our footstep line Trace by profile left function and I initially ran into problems when I was testing this out and I just couldn't figure out what was going on and let me show you what I was running into so what I'm going to do is I'm going to draw debug for duration here compile and save and let's just test this really quick I'm going to step on the water and you'll see what's happening so we see that it's actually hitting something above the water right we see that it's hitting something it's not actually hitting the water it's hitting something above the water you see where those squares are and so if that's happening to you so this is what I needed to do this is just a good troubleshooting tip so we're going to do a print string after our line Trace by profile I'm going to append something onto that print string and what we're hitting that's what we're going to append and then what we're hitting is our hit actor here and that way we're going to be able to troubleshoot quickly what we're actually hitting with every footstep so if I step into that water what we're hitting is water Body Ocean so what we need to do and this is the first time that we've done this in our line traces what I need to do is I need to assign our actors to ignore here our water Body Ocean because you might think well I want it to hit our water Body Ocean but the problem is our ocean blueprint even though it's across the entire world it's obviously not going to be under the ground and we could have water levels that are at different levels under the ground so the way we solve this problem last episode if I just zoom out here to show you we assigned all these water planes around our ocean and that's what's actually being hit when we step into the water it's not the ocean itself it's the water plane and so I'm going to do the same thing over here we're going to have a water plane that's right here but in order to get it to hit the water plane we have to tell the line Trace to ignore our ocean so let's go back to that function and the way we tell it an actor to ignore is we can just drag out a pin here and say get actor of class and to be honest this is kind of inefficient the way I'm doing this here the reason it's inefficient is that every single footstep every time we do this line Trace by profile we're going to get an actor of class it's not too bad because we're just getting a single actor but we're going to fix this in an upcoming episode where we'll make it more efficient but for now this will do so we're going to do water Body Ocean here and when we get that water Body Ocean of class and there's only one ocean in our world so we can just get one then we can connect this up to actors to ignore it's automatically going to make an array right there and then we can compile and save and we can once again print what we're hitting and see what we're hitting now so what we're hitting is the tundra Rock now we're not hitting the ocean water body so let's go back to our animation blueprint we can delete out all of this connect this up just like that I have to go back into our footstep line Trace by profile right now because we have a left function and we have a right function and we're going to do the same exact thing here get actor of class so water Body Ocean and connect this up move this down here compile and save all right now that we have these two functions ignoring our water Body Ocean we have to tell it okay when you hit something when you hit Niagara water what are you going to do but even before that we need a way in which this can identify that it just hit our Niagara Water blueprint so for that I'm going to go back to our shallow water interactive water body and we're going to handle this the same exact way we handled this with our ocean you heard me say that so what we're going to do is we're going to add a mesh and we're just going to add a plane directly to this this is going to be our water plane if I come over to the viewport then I can see that plane in relation to the actual Niagara system and what I'm going to do is scale this up if I scale it up to 2021 and I'm going to make it about two units above the Niagara system just so it's just barely above it and then what I'm going to do I'm just going to make this into a window because if we go back outside what we did last episode with these water planes we've got to give it an SM water plane and our Mi water one so I'm going to change our static mesh to SM water plane and then our material I'll change that over to Mi water one and between those two things those are identifying that we're hitting water and we also need to change a few other things down here because if I scroll down you see that this is different our Collision presets here compared to here here so I'm going to change this to default and I can uncheck generate overlap events so let's compile and save this blueprint and now we can actually test in our cave and see that we're hitting water now it's not going to do any Ripple effects but it should have our actual Splash effects alright so you can jump into the water and there we go so if you're getting your Splash effect if you're seeing your line traces there then you know you're good but I notice here that the water just got a lot darker and the reason that that happened let me go back into the blueprint so what we're going to do is we're going to say we're going to make this water plane hidden in game check it just like that and then when I actually play from here it's going to be back to our regular water minimize this yeah there's our regular water there but we still get our Splash effect all right so far so good but now we need to get these two things interacting right so we need to tell it okay when that line Trace by profile hits the water plane we need to see does it implement the interactive water interface because if it does implement that interface then we're going to pass data into this Niagara system and that's where we're going to trigger the Ripple effects wherever we're hitting so we'll go back over to our animation blueprint and into these functions here so what we're going to do is we're going to get our hit actor here we're going to check to see does it Implement an interface in the interface that we're checking is the Niagara interaction interface that we just set up so Niagara interaction does it interact and then we can drag out here and do a branch and put this in a position connect it up because if this is false then we're just doing a regular thing then it's not Niagara Water we are good but if this is true so if this hit actor does implement this interface then what we can do is drag it a reference to that hit actor and get a reference to that interface function the footstep Niagara Water function that we just set up in that inner interface so this right here go back to our ABP third person character connect this up and we need to connect up our actor to it because that's the actor that's actually implementing the interface and because we put in our two inputs right here hit location and hit size that's what's showing up right here so our hit location is going to be the location and the size you know what for footsteps here I'm just going to set it to 20. but in the future we could always change this like depending on the size of our character we could have a switch and change the value you get the idea and then last but not least I'm going to put in a few reroutes here because we got to drag this out here and we still got to do a return node following the footstep Niagara Water because we're still going to have Splash effects spaghetti's looking a little messy but it should work just fine so compile and save this so that's one of the functions so now what we can do is copy these three nodes so hold Ctrl Ctrl C come over to our footstep line Trace by profile left and we're going to do the same exact thing paste them up here connect this up there hit actor goes here hit actor also goes to our interface location to hit location hit size is still 20 that's looking good false is down here rear route reroute move these out stop doing the preview instance up here because that's an annoying pop-up connect this up down here so if you've got all that so I would flip between these two functions just make sure you're not missing anything if you've got all the same number of lines you are good to go so compile and save all right so now when our line Trace hits something if the actor that it hits can Implement that interface it's going to send information over that interface the problem is the actor that it's going to hit the shallow interactive water body it's not yet implementing the interface so on our blueprint here we need to go over to class settings exit out a hidden here expand interfaces and I noticed a bug in 5.1 so for whatever reason in 5.1 there's no add option for implemented interfaces and I saw that Unreal Engine identified a fix for this for 5.2 but we're in 5.1 right now so if you're watching this episode on 5.2 you could just hit add up here and select your interface but if you're on 5.1 like I am currently we have to come down here under add and we have to search for Niagara interaction normally you would do this right up here and select it here and then when we do that we have our interfaces on the left hand side here so I'm going to go back over to our event graph and I'm going to move down underneath our spawn water drop particle here and we'll right click on this and Implement event and that's our interface so this is what's going to be called whenever this gets hit so I'm going to go back over to shallow interactive water and now we need to set this up so the first thing we want to do whenever we get a hit we want to get a reference to our water surface Niagara system and we want to set a boole parameter to stop killing particles so this is going to be kill particle and set to false and the next thing we want to do is we want to get a reference to our spawn location paste that in and hook this up but now it's not going to be in the center of our water surface Niagara system it's not going to be this because it's going to be instead whatever location was our hit this is the location that our footsteps are actually hitting the water but I want to caveat that slightly because what we're going to get is just the X and the Y we're not going to get the Z because we always want the Z to be the same level at wherever our water surface Niagara system actually is and that makes sure that the particle is at the right level of the water and that's the reason I dragged out a vector and did a break Vector from here so from here what we can do is we can do a make vector and we could just hook up the X and the Y and then connect this up here and for our Z we can just get the same exact thing we just did paste that in get World location we're going to have to break this so right click split struck pin and then return value Z connect that up here and I'm going to put in a little reroute for our Vector alright so then we have this hit size variable right here but if you remember back in our Niagara system itself we don't have this set to a variable yet this is just set to particle radius of 20. so that's what we got to do in our Niagara system and I can expand user exposed here we're going to create a new user exposed variable under make new common and this is going to be a float and we're going to call it hit size and for the particle radius here so what I'm going to do is at a minimum it's always going to be a size of 20. but I'm going to add whatever our hit size is so we're going to do a plus sign add float and it's going to be 20 plus our hit size here so at a minimum tiniest footstep is still going to be a size of 20 but this could potentially be giant alright so we'll save our Niagara system back to shallow interactive water so we can drag out a reference to hit size I'm going to do a reroute node and then drag this out here we'll do another reroute move both these down so we can get a reference to our water surface Niagara system and from here we could set a float parameter connect this up here and this is going to be hit size connect this up here and compile this and I actually made a mistake because back in our animation blueprint we probably want to set these to zero so unless our feet are pretty big you know what we can do let's set them to 10. so each hit is a little bit more than a water drop but it's not gigantic so we'll just set this to 10 and that way the overall hit size will be 30. so back to shallow interactive water the last thing we need to do is set our spawn rate so up here we can get a reference to the water surface NS spawn rate again and this for footsteps I'm just going to set it to five and I found that that worked just fine and the last thing I found that I needed is instead of a delay for next tick I'm going to set this to be a re-triggerable delay and the reason it's a retreat delay we're going to keep it at 0.2 seconds but the reason it's re-triggerable is that every subsequent step or every subsequent interaction with the water should prevent the particle from being killed but if 0.2 seconds elapses then what we're going to do is Select this copy this set our spawn rate down to zero and we're also going to do the same thing for kill particles so I'll get a reference to both of these paste them in put them in first I don't think the order matters but I'm just going to do this just to be in line with my notes and so we are ready to test this let's compile and save and play from here there we go but we still have the water drops in the middle so we can turn those off and the other thing is you see the ball just kind of as I'm moving you see the ball going boop boop boop because it's basically existing for 0.2 seconds that spawn particle and we're going to take care of that by the end of the episode but just it's good to be able to visualize what's actually happening in our Niagara system to make the ripples occur all right so before we go on I'm just going to disable that line Trace down because that's starting to annoy me so we'll come over here I think it was this first function yeah draw debug to none so now it's time to get our flamethrower interacting with the water the same way you saw on the intro and so for that we got to create a new blueprint interface function and the reason is it needs one more variable other than just a hit location and hit size it also needs a hit velocity because we need to tell it in what direction is the flamethrower hitting the water so what we can do is right click say copy and then paste control V and we're going to rename this instead of footstep Niagara Water gameplay ability Niagara Water and we just need to add one more input for our hit velocity and this one's also going to be a vector and if you click all the way on the edge here you can actually drag this up you can sort these little differently like all the way in the edge drag it up boom all right compile and save our blueprint interface and we are all set with this blueprint interface so we can close out of that I think we're also all set with our animation blueprint so I'm also going to close out of that and to incorporate our hip velocity into this Niagara system the only thing on the Niagara system we need to update is this set particle's position so instead of this tiny little value the 0.1 there what we're going to do is for the B we're just going to do an add vector and we're going to keep in the a that 0.1 y because that's always going to ensure some particle movement even for a footstep with no velocity and for the B we need a hip velocity user parameter so again under user expose plus sign make new Under common I'm going to do a vector hit velocity and we could just plug that in directly but what I found is that hit velocity is a little bit too intense actually a lot too intense so we need to divide it by a hundred so a hundred hundred hundred because otherwise the particles like boom and you don't even see anything so we take our hit velocity move it into the a position here so if you got all that you are ready for gameplay abilities to be integrated with this so save this Niagara system and now we're going to build on we set up last episode in our gameplay ability fire so back to content drawer under content under blueprints under gameplay abilities gameplay ability fire in this we originally set up all the way back in episode 26 and then 27 for our flamethrower so last episode we set up this check and update Dynamic force over water function and that's being called every event tick right here so I'll go back into that and what that's doing is initially it's assessing okay are we spell casting standing still and actually I messed this up last episode so this should be a channeled spell and then connect this up here just like that because we're checking to see okay are we spell casting standing still and is it a channeled spell is it able to be activated or deactivated and only if all those things are true then what it does is it goes and it does a line Trace by profile to identify are we hitting water and then it updates the primary Dynamic Force component that we set up last episode to work for our ocean and we're going to keep all of that because that's how it's going to work on our Ocean or on our landscape water bodies but now we need to set it up for the Niagara system and we'll start the same way we did on our animation blueprint we're going to do a get actor by class get actor of class first one here I'm going to move all of these down a little bit connect this up here this is going to be once again our ocean water Body Ocean connect this up here connect this up here and then once we got that we can come over here again and expand this and get our hit actor and say does it implement the interface in the interface we're checking is Niagara interaction after this true here we're going to do another branch connect it up just like this if this is false that's where it's going to do the set actor location here so I'm going to move all these down connect this up but if it's true we're going to do the same exact kind of thing we just did so we get our head actor and we say gameplay ability Niagara Water that's the interface function that we're implementing connect this up now for the hit location we're going to connect it up right from here this is our location and then for the hit velocity so for that we've got to come all the way back down to here because we crafted this line Trace last episode to reflect the direction of our flamethrower and what we're going to do is from here we're going to do a minus vector enter and subtract this from it and what this is actually doing is it's getting the start in the end position of our line trace for our flamethrower it's basically saying how far out is our flamethrower going and with that Vector it's basically incorporating then a Direction but also an intensity of how far out that line Trace is going and we're going to use that as a velocity so I'm going to move over here and it's not a true velocity though and connect this up just like that and that's really why we need to divide it by a hundred because it's getting a total distance and it's getting that in like a single tick and then we need to specify a hit size here so for this I'm just going to make it let's do 20 because it'll be 20 plus 20. and you could set this to anything you like whatever you want for your flamethrower and so now I'm going to compile and save and because we have this new interface function we're going to go back to our shallow interactive water here and we have a footstep Niagara Water but if I expand under default I'm not sure why one's not classified and the other is that doesn't really make sense to me but we have a second interface function here I can come back over and directly underneath event footstep Niagara Water we can right click here Implement event and this is for our gameplay ability and basically what I'm going to do here to start is I'm going to copy everything that we just did because we're going to utilize all of it so copy paste connect this up just like this and connect up our hit location here connect up our hit size here but we just have one more thing which is our hit velocity so for that I'm just going to make some space for it move this down here and actually I'm going to move all of this out just a little bit we can get our spawn location paste that in and change that over to hit velocity connect this up here connect this there get our hip velocity right there and connect it up there a couple of reroutes but actually I messed up here because we don't want to just connect up the hip velocity I'm going to disconnect this the reason is that it's the same thing whereas if we're pointed downward we don't want the particle to actually go downward we still want the particle to keep being at the water level so I'm going to take exactly what we've got here copy those paste them here and the Z is actually going to always be zero because we always want the velocity to not be down not be up just to always be across the water and then I can take this hook it up and put in a reroute the last thing here for the flamethrower because it's kind of intense I'm going to change the spawn rate from 5 to 30. and you could play with that setting you could try it out with different settings and see what you like best but I found that setting this to like 30 or 20 it just gave kind of an even stream across the water yeah how about we tone it down a little bit to 20. and the last thing here for the flamethrower I found that setting a re-triggerable delay to about 0.5 seconds had a better effect and that's going to be used for all of our gameplay abilities so compile and save this and we are ready to test with our flamethrower so in order to do that what I'm going to do is zoom out here we're going to get both our flamethrower and Fireball we set up last episode out here on the beach copy and paste them move them in into our cave it's moving day and the other thing here just to get it looking like you saw on the intro let's go up to Windows go to the environmental light mixer and change this over to normal and what I did if I scroll down down down to our exponential height fog under the emissive here I just made that a little bit more foggy so raised it a little bit and I also changed it to a kind of a greenish tint green blue something like that gives it kind of an eerie cave-like feel and the last thing I did is back in our third person character blueprint only need to do this if you have a post-process effect set up on your third person character blueprint like we did for our damage effects back in episode 43 but we're just gonna increase this minimum brightness to something like 1.5 and that's going to make it a lot darker in our cave compile and save that and then right click play from here just start with our flamethrower because Fireball will not yet work all right so here we go and there's our flamethrower in action with all the ripples accompanying it all right so now it's on to our Fireball so we got to go back into the content draw our back and a blueprints back into Spawn from abilities from last episode BP Fireball and last episode we finished that by once again doing the check and update Dynamic force over water function here the same kind of thing that we've been doing with all these line traces we have to get actor of Class Connect this up here this is going to be our ocean water Body Ocean connected up down here move it down a little bit and connect this up here so then on our Fireball blueprint we can use this direction that we set up back in episode it's 30 and 31 to make this Fireball I found that did a really good job with the hit velocity so we first have to do the same kind of thing here where we got to get our hit actor and we need to check to see does it implement the interface in the interface is Niagara interaction and then we Branch following this branch connect this up once again move this down move all of these down connect it up to the false move these down even further because here is where I'm going to get reference to our Direction and I'm also going to get a reference to our intensity and I found that multiplying this by about 40 that got a good effect so Direction times 40 and the reason we need to multiply it by 40 is simply because we're dividing by a hundred within the Niagara system and the direction is a normalized vector here meaning it's only up to one so that's where we've got to make this value higher so from here we're going to multiply connect this up and then once again we can get a reference to our hit actor and we can implement the gameplay ability actually call I should say gameplayability Niagara Water function connect this up here hip velocity is going to be connected just like this for our Fireball I'm actually going to make this a lot larger so a hit size of 80 and then I hit location here we're going to get our location pass that right in compile and save this and back in our shallow interactive water body you know I think with all this it's going to work just fine with our Fireball because we're already passing in the hit velocity hit location hit size all is going to be well but the one thing I do want to update just to make sure that this plays properly with our footsteps is we want to update our hit velocity for footsteps to be zero because otherwise it still could be using the previous velocity from like our flamethrower when our footstep hits so we can come down here and get our hit velocity from down on here copy that and what I'm going to do is just move this out a little bit for our footsteps make some space paste it in here set this to zero and then connect it up all right we are ready for our Fireball compile and Save foreign you could use this in conjunction with your flamethrower I'm just going to make a full screen just to see how this goes here we go ready wow a lot of balls flamethrower is still working just fine what steps working just fine so finally guys we get to hiding the balls so we got to go back over to our Niagara system here and I did this a really simple way so all I did is I took the same exact material that's on the water mesh itself so if I expand override materials this water material instance here and I assign that to our ball so I went under mesh renderer and then under override materials enable material overrides plus sign here come down here index 0 and just assign our water material instance just like that and we can save this and now we should be able to exit out of every single one of these things and do one final test and everything should be working except the material should be entirely hidden all right lane through our Fireball here we go we get splashes Fireball yep flamethrower and there you have it ladies and gents so that concludes our episode for today with the footsteps I thought about having a particle kind of permanently attached to each of the sockets and then be moving as our character is moving but I thought that would be a lot of extra work and we already had this setup in place for each individual footstep and also I didn't think that it would look that much better maybe a little bit better so if you want to try that out if you want to try to have your particles continuously move as your character is in water I think you would have to have continuous line traces down just to confirm that the character is in water then by all means feel free to create a video and if it's good I will post a link to it in the description below and for those of you following the series I want to give you one last treat so what I want you to do is go back into the content for our core folder into your AI folder take your BP adversary character that we've created over the course of several episodes drag that into the world could be anywhere next to our water body so something like that is totally fine might take a few seconds to load and then right click across the water body and say play from here and you should see your AI character creating splashes jumping in the water basically having all the same effects that we've got for our main character so that concludes our episode for today and over the next few episodes these are going to be a little bit different than normal they're going to be shorter more to the point because I want to finish out a few things in relation to our underground cave environment here and the first is related to our water so everything looks good when my camera is above the water but when it goes below plane disappears and also we've got no post process material under the water so that's exactly what we're taking care of next episode so I hope to see you there
Info
Channel: NumenBrothers
Views: 6,775
Rating: undefined out of 5
Keywords:
Id: 5aROMA2KQPc
Channel Id: undefined
Length: 45min 1sec (2701 seconds)
Published: Sat Mar 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.