Hello and welcome back to this channel!.
At the end of this month will be released
a remastered version of a videogame that has
accompanied us during our childhood, medievil.
As tribute we are going to realize the death
vfx in Unity.
Analysing the gameplay trailers that have
been recently released, we can subdivide the
project into 5 steps;
setting up a custom scene and animate a character.
creating a dissolve shader for the mesh of
the character
creating 4 VFX
creating the trail renderer
coordinate all this things with a script
First of all we created a Unity 2019.2.5f1
project with the LWRP template and from the
package manager we installed the preview version
of the visual effect graph that we’ll use
to create the vfx.
To set up the scene, we imported a model found
on Sketchfab and created by caiozed that represents
a graveyard environment.
We created the materials and moved the props
in front of the camera trying to find a good
spot.
To improve the lights and the emissive materials
we also added the post processing stack to
the camera and set the value of the bloom.
We added two more cameras and with a simple
Manager we switched between the gameobjects.
As character, instead of the zombies, we used
our mascotte Nutty.
We created two animations, one for the idle
state and one for the death.
In the death animation we placed, some seconds
that the movement is ended, a custom event.
We’ll see soon the reason.
We also added a spawnpoint in the hyerarchy
and used it to spawn Nutty in a desired position
from the manager.
Now the dissolve shader.
After few seconds that the enemy dies, his
body dissolves.
To realize this effect we created a new PBR
shader and added some simple nodes.
Really important here is the alphaclipthreshold
parameter, besides exposing it to the inspector,
we changed his reference name with a simpler
one to set it’s value via script.
It determines how many pixels of the simple
noise texture that we are going to add are
considered visible.
We added the simple noise node and colors
for the albedo and emission inputs.
The alpha input is connected with the output
of the simple noise so that we can clip his
value with the alphaclipthreshold.
As u can see, changing the threshold value
set the amount of visible texture.
We need to change this by script so we created
a script called Nutty.
In the Start method of the class we create
an instance of the dissolve material, initialize
the value of the alphaclipthreshold to 0.15f
and get the reference of the animator.
In the Update we listen for a space key pression
and when it occurs we play the death animation
of Nutty.
As told, the death animation has an event
on it’s timeline.
This event calls the Die method of this script.
So, after few seconds that Nutty is on the
ground, it makes two actions.
The first is a recursive method that, starting
from the top level gameobject of nutty, iterates
through each child checking for a mesh renderer.
If the child has a mesh renderer, the default
material is replaced with our dissolve material.
The second method called DissolveObject is
a coroutine.
It increments the value of alphaclipthreshold
of the instanced material until it gets a
desired value, 1 in this case.
The nested IF with 0.8 will be used to handle
the vfx stop time.
Time to start with particles, we used the
visual effect graph to achieve our results.
We recognized 4 VFX, the first, more wide,
is a constant burst of pink sfirs spheres.
These particles move along the vertical axis,
have different sizes and are intermittent.
The second one is a burst of thin violet lines,
it is positioned near the head of the zombie.
The third, almost invisible, is a sort of
dark violet smoke and The fourth is a ghost
that spawns also near the head and fly away.
The first graph is for the pink spheres.
It emits 100 particles at seconds with a capacity
of 300 max particles at the same time.
Lifetime is low and the interesting think
is the block “set position from map”.
As you can see, thanks to a point cache file,
we said to the particles to spawn from the
shape of Nutty instead of a simple box for
example.
The tool to create the point cache is included
inside the visual effect graph package.
It accept a single mesh so we needed to merge
all the parts of nutty to create it.
Another important thing is the color/alpha
over life, here we created the blink effect
alternating full color with transparent spaces.
The second graph is similar to the first one,
it has a low spawn rate and particles are
stretched along the X axis thanks to the set
scale block.
Third graphic uses a flipbook to create animated
particles.
To use flipbooks you need to add a flipbook
player in the update and choose flipbook in
the uvmode of the output.
We used a flipbook downloaded from the unity
blog.
Fourth graph is the ghost.
Here we have a single burst spawn block with
1 particle emitted.
To make the ghost appears full colored without
details at the beginning and with the original
colors at the end we used the same texture
two times and we played with the color/alpha
over life blocks.
To recreate a perfect result we needed to
paint a flipbook of ghosts but since our manuality
is not so good we downloaded and modified
a general ghost image.
Last but not least, the flying soul.
To create it we first tried creating a flipbook
with adobe after effect but with bad results.
Then we realized it could be created with
a simple trail renderer, so we painted in
photoshop a similar shape and started to code
the movement of the trail.
The movement follow a sin wave, the code is
pretty simple.
We used a lerp method to stretch the trail
over time because the soul becomes bigger
during his travel.
We moved the trail constantly along the Y
axis and with the output of the cos function
in the Z axis.
To handle the effects We added a begin and
stop event in the vfx graph and we synched
all the calls in the nutty script.
What do you think about this final result?
Let us know in the comment below if you liked
the video and subscribe to the channel.
Thanks for watching, see you the next week!
