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 AusAndrew19 · Jul 03, 2012 at 09:04 AM · explosions

How to make a barrel explode after being shot

Hey, I'm creating a game and i need a barrel to explode when i do damage to it. I'm fairly new to scripting so im not too sure how to do this. anyone with information on this could help me out i would appreciate it. thank you.

Comment
Add comment · Show 2
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 AlucardJay · Jul 03, 2012 at 09:15 AM 0
Share

I would suggest one of 2 methods. 1 is to destroy the barrel, 2 is to move the barrel around.

1/ Destroy the barrel and replace it with a particle effect(explosion) and instantiate a broken barrel

2/ use AddForceAtPosition to give the illusion of the barrel being 'hit' by the bullet.

The support docs seem to be down at the moment, so look in your computer where Unity is installed. Somewhere like file:///C:/Program%20Files/Unity/Editor/Data/Documentation/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html

online now working :S http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html

avatar image AusAndrew19 · Jul 03, 2012 at 09:18 AM 0
Share

okay mate will look into this. Cheers :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by FLASHDENMARK · Jul 03, 2012 at 09:20 AM

Give your barrel some health.

When you shoot the barrel decrease the health.

When the barrel gets shot check to see if the health is equal to or less than 0. If it is less or equal to 0 then your barrel should explode.

You should most likely Instantiate a explosion prefab to make it look awesome.

And optionally you can add forces to the rigidbodies around you. This would make all the non-Kinematic physics objects fly away as if a shock wave hit them.

That is just the breakdown of what is likely going to happen, to give you an overview of what needs to be done so you can get your barrels to explode.

If you do not understand feel free to ask.

Comment
Add comment · Show 12 · Share
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 AusAndrew19 · Jul 03, 2012 at 09:22 AM 0
Share

To be honest i understand what needs to be done. But im not sure how to go about it. I have tryed finding a tutorial or even a prefab for this but i cannot. So to be honest if you know of a tutorial i would really appreciate the link. thank you mate.

avatar image FLASHDENMARK · Jul 03, 2012 at 09:29 AM 0
Share

Well, just a quick Google search lead me to this:

http://answers.unity3d.com/questions/172364/sendmessage-crashes-unity-editor.html

He has got a pretty good setup of what you are trying to archive, maybe it will help you?

avatar image AlucardJay · Jul 03, 2012 at 09:31 AM 0
Share

forgot about AddExplosionForce =]

Some other things to look up :

Raycast to object (shoot)

http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenPointToRay.html

From the collider information, Destroy the collider gameObject.

http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html

Also from the collider info, instantiate a particle effect, and also instantiate a prefab of a broken barrel.

http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

avatar image FLASHDENMARK · Jul 03, 2012 at 09:32 AM 0
Share

Definitely worth taking a look at, yes.

avatar image AusAndrew19 · Jul 03, 2012 at 09:40 AM 0
Share

That link you gave me orange, Is what i need. Its perfect now i just gotta create a explosion prefab and im ready to go! Thanks.

Show more comments

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Need a script 0 Answers

Script to calcualte the player's distance? 1 Answer

Detecting serialization reload in editor 1 Answer

How to make a cooldown on a script 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