Polishing slide : sand particles

estimated time : 7mn
ingredients needed : Unity, Playmaker
(this recipe is part of the footvolley game menu )

It’s time to do some polish by adding some particles to our sliding move.

First, add a particle system to the stage like in the recipe.

Then include these settings :
(just for the example, you can play with the settings to get better effects)

  • Duration : 2
  • Start lifetime : random between 0,3 &0,8
  • Start speed : 5
  • Start colour :  choose the  colour to match the sand background, but make it darker to give some contrast.
  • Gravity : 0,26
  • Simulation speed : 2

01:23

Change the renderer parameter for a pixel render to get pixelate effects, as smooth particles tend to render wrong on  raw pixellated game.

Then, change the emission rate to get more pixels flying.

Change the cone shape settings in order to have pixels emanate from one precise point and get the dispersed all around the cone with these values :

  • Angle : 20
  • Radius : 0,01

 

02:29 Layer importance

By lowering down the position of the particles, we can see on the gameplay screen that the particles are displayed  behind the game field image.
It’s because the sorting layer in the renderer parameters is set to default, we need to place it above the other layers, so set it to the same level of the characters (as in create a 2.5 character step).

Now modify the gravity to 1,92 to have sand particles going down and slow down the simulation speed to 1,5.

Now that we’re fine with our particle effect, it’s time to add it in game when we want.

 

We rename our particle system in « sand_burst » to know what we’re dealing with at a glance, and we move it in our resources folder to be able to instantiate it later in the simplest way.

Then we delete it from our scene view.

 

04:14

Go into our player controller script to instantiate it as we slide.

Add the add_burst method  :

 

void add_burst(){
//instantiate the sand_burst particle gameObject from the Resources folder
  GameObject instance = Instantiate(Resources.Load("sand_burst", typeof(GameObject))) as GameObject;
//then set the position of new created gameObject at the player position         
  instance.transform.position = _controller.transform.position;
    }

Then go into our player1 FSM, on the sliding state we add the send message « add_burst » action to call our add_burst method while we slide.

We test it :

So far it add one single sand burst right where our player was when he starts sliding. It was just to check if our code works well; and it does 😉

 

05:00

Now onto the upgrades,
we want the sand bursts to be displayed all along our slide.

To do this we’ll call the add_burst method intermittently, and add one more thing to our sand burst prefab : a destroy event, because if we leave it as now, we ‘ll have tons of particles effects over but still present on the stage.

So we go on the resources folder and simply add our destroy script, with a lifetime of 0,5, to the particle effect.

 

05:17

In order to test the multiple call to the particle effect method  create a new state “sand burst” in our player1 Fsm.
Copy onto it the send message action to call our method (don’t forget to remove our previous call to it on the sliding state).

Replace it by the « next frame event » action, creating a new event « sand burst » for the occasion, add the sandBurst transition and link it to our new sand burst state.
It immediately calls the sand burst method, and after that go back to our sliding state.

This makes a quick loop calling on each frame a sand burst. As you can see while testing, it’s a little messy, we’ll have to polish it up a bit.

To do so, remove our next frame event, and add something else:

The “send event” action, and  fill the delay parameter to 0,23.

By doing so it send the sandburst event every 0,23 sec, as the sand burst calls immediately go back to the looping state; it continues the calls every 0,23s until our slide is finished. Giving better results.

Leave a Reply