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 jmgek · Jan 03, 2013 at 11:01 PM · explosions

How can I make the explosions I have on a object spawn on the mesh

I am not trying to destroy the object, I am just looking how to make the "explosion" instances blow up on the outer mesh. I am shooting at it with a gun and just want to see random explosions once in a while. I was thinking a rand type of function but I dont know what function I use to get the GameObject mesh.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Loius · Jan 03, 2013 at 11:39 PM

You'd have to find a random triangle in the mesh, then find a random point in that triangle.

int triangle = Random.Range(0,mesh.triangles.Length / 3) * 3;

Then your three verices are mesh.vertices[triangle], [triangle+1], and [triangle+2].

There are a few ways to get an object's mesh; the easiest way is probably gameObject.GetComponent().mesh, but check out the script reference too.

Edit - Sigh, and after "GetComponent" you need a Less Than symbol, then "MeshRenderer", then a Greater Than symbol.

Comment
Add comment · Show 1 · 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 manard2 · Jan 04, 2013 at 01:06 AM 0
Share

So I can put?

function start(){ int triangle = Random.Range(0,mesh.triangles.Length / 3) * 3; }

if (die){ Instantiate(explosionPrefab, transform.position, transform.localRotation); }

avatar image
0

Answer by strachpr01 · Jan 04, 2013 at 12:50 AM

you could attach the explosion to the bullet you are firing, you can then get it to explode on impact on anything by instantiating the explosion where the bullet is at the collision then just destroying the bullet.

Comment
Add comment · Show 5 · 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 manard2 · Jan 04, 2013 at 12:53 AM 0
Share

I already have what you are advising. I need a random explosion on what I am hitting, I already have my instance on my bullet prefab.

Thanks though.

avatar image strachpr01 · Jan 04, 2013 at 01:04 AM 0
Share

the only thing i could think of would be to use empty game objects on the mesh and use Random.Rage to select the spawn points in a GameObject[] the just instantiate them at the chosen spawn point? its a long way round but could be a solution if no one else answers :)

avatar image manard2 · Jan 04, 2013 at 01:08 AM 0
Share

Yeah I was thinkning that. But the object I need to explode is a prefab. You think that I can get a random position on the outer edge of every prefab?

avatar image strachpr01 · Jan 04, 2013 at 01:19 AM 0
Share

personally i would make the empty game objects part of the prefab then you can still access them through the GameObject array

avatar image jmgek · Jan 04, 2013 at 01:21 AM 0
Share

That way I can also choose where the explosiuoons dont blow? also can I make the empty game objects in max?

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

11 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

Related Questions

Detonator Issues 0 Answers

Help with Collision Detection for explosions? 1 Answer

Make CharacterController act like rigidbody on explosions 1 Answer

Delete Explosion After 1 Second Script Not Working 2 Answers

Tutorial: Space Shooter - 10 Collision not detected? 4 Answers


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