- Home /
Bomberman like explosion
Hi I bet everyone here knows what bomberman is, ok, so I am making a game like bomberman but I don't know how could I achieve the same type of explosion, for now I created a bomb that maes 4 raycasts, for the 4 diferent directions, and if it is on range it will send the message to explode. So, this explosion type is working, but could be better, in bomberman a explosion lasts like 0.5 seconds, and not just the explosion moment, and I wanted to achieve that, but with the script that I currently have, if it lasts 0,5 seconds it will just go on and destroy everything in it's max range ( if the first cube is on range is destroyed, and if it finds another cube in the same line within the raycast range is also destroyed, and not only the first one), also, this game made in unty shows a explosion like in bomberman, I wonder if the explosion is made by instantiating colliders according to max range, or if it's a raycast, and also, what I wanted to know is how do I make those kind of explosions effect? is that particles is that a texture?
here's my current bomb script:
#pragma strict
var fire : float = 3;
var timer : float = 3.3;
var damage : int = 1;
var hasReceived : boolean;
var distance1 : float;
var distance2 : float;
var distance3 : float;
var distance4 : float;
function Update ()
{
timer -= Time.deltaTime * 1;
if (timer <= 0)
Explode ();
if(GameObject.Find("Capsule").GetComponent(Player).fire == 1)
fire = 2.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 2)
fire = 4.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 3)
fire = 6.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 4)
fire = 8.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 5)
fire = 10.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 6)
fire = 12.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 7)
fire = 14.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 8)
fire = 16.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 9)
fire = 18.90;
if(GameObject.Find("Capsule").GetComponent(Player).fire == 10)
fire = 20.90;
}
function Explode ()
{
hasReceived = true;
var Front : RaycastHit;
var Back : RaycastHit;
var Left : RaycastHit;
var Right : RaycastHit;
if(Physics.Raycast(transform.position, Vector3.forward, Front))
{
distance1 = Front.distance;
if (distance1 < fire)
{
Front.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
if(Physics.Raycast(transform.position, Vector3.back, Back))
{
distance2 = Back.distance;
if (distance2 < fire)
{
Back.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
if(Physics.Raycast(transform.position, Vector3.left, Left))
{
distance3 = Left.distance;
if (distance3 < fire)
{
Left.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
if(Physics.Raycast(transform.position, Vector3.right, Right))
{
distance4 = Right.distance;
if (distance4 < fire)
{
Right.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
yield WaitForSeconds (1);
GameObject.Find("Capsule").GetComponent(Player).bombs += 1;
Destroy(gameObject);
}
function ApplyDamage ()
{
if (hasReceived == false)
Explode ();
}
If, like bomberman and that game you linked to, you are using grid based movement, I would skip raycasting all together. You would need a 2d array storing all the spaces, then when the bomb explodes, it would check the appropriate spaces around it and set them to a "bomb explosion" state.
that seems complicated, I have no idea how I could do that
bump, I was hoping to get a basic idea of how I could do that array thing
Its less complicated than doing it any other way, honestly. What you want to do is declare a 2D array of your tile objects and fill it with them with the position of the tile in the scene corresponding to an entry in the array.
each tile object could contain a particle emitter that will fire according to the range of the bomb. so when the bomb is set to explode, it would just call some "explode" function on the tiles around the tile containing the bomb. You can work that logic in any way you want so that a bomb could explode in only diagonal and horizontal directions, or in a range of all directions. using a grid should make all the calculations easier
Your answer
Follow this Question
Related Questions
Raycasting fail 1 Answer
If Raycast Hits Air 4 Answers
Accessing colliders, in if statement 2 Answers
How do I register damage from the actual sword? not Raycast 1 Answer