Water gun FX from Pokemon games in Unity

Hello everyone, welcome back.

I am back after a long break and in today’s post we will recreate water gun effect from Pokemon games. Super simple and easy way to do it is with VFX graph.



Intro

For this, I am using Unity version 2023.1 and I have a project setup in URP. I have already gone ahead and installed VFX graph package.

I also have the post processing volume with main modules Bloom and Tone mapping with the mode Aces.

First let’s create a VFX graph, Right click > Create > Visual effect > Visual effects graph. Let’s call it WatergunVFX.

Let’s also add it to our scene, so in Hierarchy, Right click > Visual effects > Visual effect. We will call it WatergunEffect and assign our VFX graph into Asset template slot.

Output context

In VFX graph, first we will go to Output context, and change the Main texture, I am going to use the default smoke texture.

Then check this Use soft particles option, soft particle means if our particle go through any solid object, it will fade out, and this Soft particle fade distance will determine at which distance our particle start to fade. We will keep it at 1.

In the Set size over life attribute I am going to set a curve so our particle starts small, then gets big then small again.

In Set color over life attribute, we will set some color but we want to control that from the inspector so let’s create a Gradient property. I will call it Color, and give some blueish color gradient. Drag it in and feed it into color slot.

Then in the inspector set its Composition mode to Multiply.

By doing this our gradient will multiply with color that we will feed in the Initialize context.



Spawn context

Now in the Spawn context, we will control the spawn rate, we want to do that from the inspector so, let’s create a Float property. Call it SpawnRate, give default value of 500, drag it in and feed it into the Rate slot.



Initialize context

Now in the Initialize context, we have Capacity of 32 but we are spawning 500 particles every second, so let’s increase the Capacity to like 15000. We will set the Bounds mode to Automatic with no padding.

We have set it to automatic because we don’t know the active area of our effect right now.

In Set velocity Random attribute we will set X between -1 and 1, and Z between 8 to 10. I want some waves in Y so let’s create a Total Time operator. It will give us seconds passed since our effect started.

Take Total Time operator’s output and feed it into Sine Wave operator. As the name suggests, it will give us sine waves based on our Input with defined Min MaxWe will control the Frequency from the Inspector so let’s create a Float property. Call it Frequency, give default value of 5, drag it in and feed it into the Frequency slot.

Then take Sine wave operator’s output and feed it into Y slot of Velocity ATake another output from Sine wave and feed it into the Negate operator. Negate operator will multiply our input with -1. Take Negate operator’s output and feed it into Y slot of Velocity B.

In the Set Life time attribute, we want our particles to live for only 1 second so in the Inspector, set Random mode to Off.

Okay let’s add a Set position attribute to control the spawn positions of our particles with shape Arc CircleRight now our particles are spawning from the surface of our circle, we want them to spawn from within the shape so let’s set the Position mode to VolumeAnd we want to control the Radius from the Inspector so, you guessed it. Let’s create a Float property, call it SpawnRadius, give default value of 0.1, drag it in and feed it into Radius slot.

Now our particle system is in Local space so if I rotate our gameobject, particles will rotate with it as if it is a solid object. So will set the simulation space to World by just tapping the button thingy labelled as Local in top right of our Initialize context.

Now let’s set the initial color and for that let’s add Set color random attribute with mode UniformWe don’t want different numbers in each RGB component or in simple terms we only want random color between grayscale values hence we chose Uniform. Keep first one white and I will set the second color with some high intensity (4).

Let’s set random angle for our particles so, we will add Set Angle Random attribute with mode UniformWe only want rotation on Z axis so from the Channels dropdown select Z axisAnd we want rotation between 0 to 360.



Update context

In Update context, let’s add some forces, first is obviously gravity, so let’s add Gravity attribute.

Now we want to control how far we can shoot the water, so let’s add a Force attribute. It will add a force on given axis, we want to add force on Z axis, and want to do that from inspector so, let’s create a Float property. Call it FrontForce, give default value of 1, drag it in and feed it into the Z axis.



That’s it for our VFX graph.

Trouble following along? Check out this video!



Thank you so much for reading!

Comments