Making a color bomb/flare in unity3D
Tutorial by:
- Anurag Pathak - https://anurag-pathak.itch.io/
- Shubham Kumbhar - https://shubham1911.itch.io/
- VIT BHOPAL UNIVERSITY
CSE GAMING & TECHNOLOGY (Game Programming)\
References
- https://learn.unity.com/tutorial/introduction-to-particle-systems#
- https://forum.unity.com/threads/throw-an-object-along-a-parabola.158855/
- 1. Creating the bomb (grenade) model:
- Add a cylinder .
- Attach 2 cubes to shape it as the trigger.
Preview:
2. Add Rigid-Body to the game object:
Preview:
3. Create a particle system:
4. Now in the particle system change emission (according to convenience) and shape to cylinder:
You must see a result like this:
Now create a new material:
5. Import a Smoke PNG file:
6. Select additive (soft) in shaders section:
Name the created material as Smoke!
7. Now drag and drop your smoke PNG to texture:
That's how your smoke material asset should look like:
8. Now in inspector section of particle system:
- Select the material.
- Add the smoke material you created.
9. Now uncheck the looping cause you don't want your grenade to work again and again.
10. Create a new C# script to the particle system:
////////////////////////////////////////////////////////////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//this script keeps the particle system attached to the grenade irrespective of where u start
public class positions : MonoBehaviour
{ public Transform player;
void Update()
{ transform.position = player.transform.position; }
}
////////////////////////////////////////////////////////////////////////////
11. Drag the grenade(game object) to the Particle system script :
12. Now add a start delay to your particle system to start the smoke after a while:
13. Now add the following script to your game object in order to throw (by adding a force):
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//this script is used for throwing the grenade and destrouing it after some delay
public class throws : MonoBehaviour
{
public Rigidbody rb;
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
rb.AddForce(new Vector3(0,15,15), ForceMode.Impulse);// used to apply force
Invoke("delay", 4f);//it is used to create delay in destroying the game object
}
}
public void delay() // whenever this function is called the object gets destroyed
{
Destroy(gameObject);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
14. Now add your game object to the script (rb)
15. Now the grenade is ready to get launched on your left click! :
The smoke looks kind of separated. We need to make it look smoother :
Change size of particle to size over lifetime and and change the particle system curve as followed (requirement):
16. Now to change the smoke colours:
Take example of any colour of your choice :
Now the bomb also gets deleted from the scene.
Bonus:
You can change the shape of the particle to rectangle and decrease the emission in order to make a flare out of it :