Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MadJohny · May 20, 2013 at 04:53 PM · javascriptraycastcolliderexplosion

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 ();
 }

Comment
Add comment · Show 26
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image roojerry · May 20, 2013 at 06:07 PM 0
Share

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.

avatar image MadJohny · May 20, 2013 at 07:53 PM 0
Share

that seems complicated, I have no idea how I could do that

avatar image MadJohny · May 21, 2013 at 05:44 PM 0
Share

bump, I was hoping to get a basic idea of how I could do that array thing

avatar image deek0146 · May 21, 2013 at 05:47 PM 0
Share

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.

avatar image roojerry · May 21, 2013 at 05:55 PM 0
Share

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

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to block dragging if collider hits 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges