Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by DarkScytheStudio · Dec 26, 2015 at 05:03 AM · collisionparticles

OnParticleCollision Instantiate Collision Normal

Hey all, i'm having a small problem with my Instantiate at Particle Collision script. The problem I am facing is figuring out how to instantiate a decal (which already works) with the normal of the collision object (which currently doesn't work). I have attempted to change the Quaternion.identity to various things that would work in some circumstances, but they all return an error. This leads me to believe I need to do something fancy.

I've heard about Collision.contact. Maybe there is something I could do with that.

An example of what I'm trying to do is blood splats that will instantiate on the normal of a collided object, meaning they will face the right way when spawned on walls instead of always facing up.

The meat of the script was found on another answers page and I've modified small sections to adjust to my needs.

 using UnityEngine;
 using System.Collections;
 
 public class ParticleCollisionPrefabInstantiate : MonoBehaviour {
 
     public GameObject objectToInstantiate;
 
     private ParticleCollisionEvent[] collisionEvents = new ParticleCollisionEvent[16];
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnParticleCollision(GameObject other /*, Collision collision*/){
 
         int safeLength = GetComponent<ParticleSystem>().GetSafeCollisionEventSize();
         if (collisionEvents.Length < safeLength)
             collisionEvents = new ParticleCollisionEvent[safeLength];
         int numCollisionEvents = GetComponent<ParticleSystem>().GetCollisionEvents(other, collisionEvents);
         int i = 0;
         while (i < numCollisionEvents) {
             Vector3 collisionHitLoc = collisionEvents[i].intersection;
 
             Instantiate (objectToInstantiate, collisionHitLoc, Quaternion.identity); 
             i++;
         }
     }
 }
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
2
Best Answer

Answer by DarkScytheStudio · Dec 26, 2015 at 01:09 PM

I worked on it and figured out that all I needed to do was write:

All it does is take the Vector3 normal of a collided object and convert it roughly into a Quaternion.

Much more code is needed to be implemented to wrap to objects or to cut the decal if it doesn't fit entirely onto the collided object, but it does the job for now.

     Vector3 collisionHitRot = collisionEvents [i].normal;
 
     Quaternion HitRot = Quaternion.LookRotation (Vector3.forward, collisionHitRot);

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

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

39 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Particle System Collision Mode 1 Answer

Particle Collision causes Explosion?,Explosion on particle contact? 0 Answers

How do I make my particle system detect/mark a floor collision? 0 Answers

Can I shoot a ray from a particle that hit a collider? 1 Answer

Can't find a way to add particle effects to a collision 2 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