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 Cl0ud · Nov 06, 2013 at 04:11 PM · rigidbodyinstantiateraycastparticleshit

Instantiate diffent particle for different object

Hello there , I want my bullet to have different particles when it hits different tagged object. Here is my script , but it's not working , and I don't know why!

 //Particles
 var HitConcrete : GameObject;
 var HitMetal : GameObject;
 
 function LateUpdate()
 {

  var fwd = transform.TransformDirection(Vector3.forward);

  var hit : RaycastHit;

      if (HitConcrete)
      {
      if (hit.rigidbody == "Concrete")
      var HitConcrete1 = Instantiate(HitConcrete, hit.point + (hit.normal * HitParticleSpacing), Quaternion.LookRotation(hit.normal));
      }
      
      if (HitMetal)
      {
      if (hit.rigidbody == "Metal")
      var HitMetal1 = Instantiate(HitMetal, hit.point + (hit.normal * HitParticleSpacing), Quaternion.LookRotation(hit.normal));
      }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheValar · Nov 06, 2013 at 05:23 PM

It seems like you are trying to use a raycast but you are not doing it correctly.

That being said as long as your bullet, concrete wall, and metal wall all have colliders you don't need to use a raycast.

just use

 void OnCollisionEnter(Collision collision) {
     if(collision.gameobject.tag=="Concrete"){
         //do something
     }
     else if(collision.gameobject.tag=="Metal"){
         //do something
     }
 }

NOTE: this is untested code and is just to give you the basic idea.

Comment
Add comment · Show 6 · 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 Cl0ud · Nov 06, 2013 at 07:45 PM 0
Share

And what about instantiating the particle effect without RayCast? I used RayCast because I wanted the particle effect to be spawned exactly where the bullet hits ;)

avatar image TheValar · Nov 06, 2013 at 08:30 PM 0
Share

Would it be precise enough to just spawn the particle effect at the location of the bullet when it hits? Also the Collision class has an array of contact points http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html so if your bullet has a sphere or capsule collider you could probably get preciscion very close to a raycast

avatar image Cl0ud · Nov 06, 2013 at 08:45 PM 0
Share

$$anonymous$$y problem with the script was that I have 2 object with box collider , one tagged as $$anonymous$$etal , and the other one tagged as Concrete. Also my bullet has a box collider. By the way if I hit these object it plays both particles effect, not just the "Concrete particle" on the object tagged Concrete.... the same for the object tagged $$anonymous$$etal. Whate can I do to make the Particle Effect recognizes which object it hit?

avatar image TheValar · Nov 06, 2013 at 11:03 PM 0
Share

I'm assu$$anonymous$$g that the metal and concrete objects are totally separate with there own colliders. Unless the bullet is colliding with both of these objects' colliders then only one effect should play.

avatar image Cl0ud · Nov 07, 2013 at 06:28 AM 0
Share

Yes , they are totally separate and both have they own colliders. But he recognition seems not to work :/

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

16 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

Related Questions

Particle Instantiation problem. 0 Answers

Stop raycasting for close distance 1 Answer

Destroying object using his name and raycast 2 Answers

Why cant this work 1 Answer

different particle on enemy second hit 0 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