Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Grenade Explosion in Unity

A topic by Azey616 created May 05, 2021 Views: 371
Viewing posts 1 to 1
(2 edits)

This is a piece of work for "Game Programming" course in VIT Bhopal. 

 Credits -

Abhigyan Chaudhary-https://abhi18.itch.io/

Pranav Kumar Vasudeva-https://azey616.itch.io/

Tutorial-

  • Creating a Scene –

Create a platform by using a cube and center it in the middle of the scene.

Add another cube which will be a box in the background

Then create a material and assign it to the box. Then change the color of the box so that it is clearly visible in background

Add a rigid body to the box by clicking on Add component

Press ctrl+D to duplicate the box and make 2 similar cubes and place them nicely in background



  • Creating a grenade-

Add a cylinder

Then add two cubes accordingly as shown and add a sphere as a knob on the top, stretch and add the cubes accordingly to make the trigger of the grenade

Apply Rigid body to the grenade.

  • Add the following script to the grenade for explosion effect.

using System.Collections.Generic; 

using UnityEngine; 

public class Frag : MonoBehaviour

 { 

float timer = 4; 

float countdown;

bool hasExploded; 

public GameObject exploParticle; 

void Start() 

countdown = timer;

void Update() 

countdown -= Time.deltaTime; 

if (countdown <= 0 && !hasExploded)

      { 

         Explode (); 

     }

void Explode() 

{ GameObject spawnedParticle =Instantiate (exploParticle, transform.position, transform.rotation); 

Destroy (spawnedParticle, 1);
hasExploded = true; Destroy (gameObject);

}

  • You will have a finished model of grenade which will explode after a certain time.


Here is a video representation of the explosion-

https://drive.google.com/file/d/17lKYxTWgdWqfqBETDivDl8Y_2o9uhzhF/view?usp=shari...

Reference Links -