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
4
Question by mgc90403 · Jan 02, 2014 at 09:49 AM · particlesonparticlecollision

How to retrieve particle collision location in OnParticleCollision

I'm trying to instantiate an explosion prefab at the location of a particle hit. (the particle system is currently shooting a single particle) Currently I have this:

 void OnParticleCollision(GameObject other) {
     myExplosion = Instantiate (prefabExplosion) as GameObject;    
 }

Which instances the explosion at 0,0,0 rather than at the collision location. I figure I need to do something like this, but it's 2AM now, and I just ain't gettin it right:

 Particle[]  particles = other.collider.particleSystem.GetParticles;

then pull the position from particles[1] - but it's bugs galore... Any takers?

Thanks!

Comment
Add comment · Show 1
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 mgc90403 · Jan 02, 2014 at 09:51 AM 0
Share

I should mention, this script is attached to the particle emitter, and it has a "world particle collider" attached as well.

4 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by mgc90403 · Jan 02, 2014 at 08:28 PM

This worked:

 using UnityEngine;
 using System.Collections;
 
 public class OnParticleCollisionAlt : MonoBehaviour
 {
     public GameObject myExplosion;
     public GameObject prefabExplosion;
     private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];

     void OnParticleCollision ( GameObject other )
     {
         int safeLength = particleSystem.safeCollisionEventSize;
         if (collisionEvents.Length < safeLength)
             collisionEvents = new ParticleSystem.CollisionEvent[safeLength];
         int numCollisionEvents = particleSystem.GetCollisionEvents(other, collisionEvents);
         int i = 0;
         while (i < numCollisionEvents)
             {
             Vector3 collisionHitLoc = collisionEvents[i].intersection;
             myExplosion = Instantiate (prefabExplosion, collisionHitLoc, Quaternion.identity) as GameObject;
             i++;
         }
     }
 }

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

Answer by MaciekXB · Jun 22, 2021 at 07:13 PM

Here is a recent example in the unity documentation https://docs.unity3d.com/2021.2/Documentation/ScriptReference/MonoBehaviour.OnParticleCollision.html

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

Answer by andrew-lukasik · Jun 24, 2021 at 11:08 AM

OnParticleCollision ParticleCollisionEvent particle system events

 using UnityEngine;
 using System.Collections.Generic;
 
 [RequireComponent( typeof(ParticleSystem) )]
 public class ParticleSystemCollisionTester : MonoBehaviour
 {
 
     public List<ParticleCollisionEvent> collisionEvents = new List<ParticleCollisionEvent>();
     ParticleSystem _particleSystem;
 
     void Awake ()
     {
         _particleSystem = GetComponent<ParticleSystem>();
         
         if( _particleSystem.collision.enabled==false )
             Debug.LogError("ParticleSystem has \"Collision\" module disabled");
         if( _particleSystem.collision.sendCollisionMessages==false )
             Debug.LogError("ParticleSystem has \"Collision\"/\"Send Collision Messages\" disabled");
     }
 
     void OnParticleCollision ( GameObject other )
     {
         int numCollisionEvents = _particleSystem.GetCollisionEvents( other , collisionEvents );
         for( int i=0 ; i<numCollisionEvents ; i++ )
         {
             ParticleCollisionEvent collision = collisionEvents[i];
             Vector3 point = collision.intersection;
             Vector3 velocity = collision.velocity;
             Vector3 normal = collision.normal;
             Debug.DrawLine( point , point + normal , Color.white , 1f );
             Debug.DrawLine( point , point + velocity , Color.yellow , 1f );
         }
     }
 
 }
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
avatar image
0

Answer by TobiasWeber · Feb 14 at 11:25 AM

Hello,
does anybody know on how to get the UV / texture coordinate for ParticleCollisionEvent? I need to draw into a texture, based on the intersection point. This is working fine for a plane, as XY map 1:1 to UV but it does not work for more complex meshes.

Tobias

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

21 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

Related Questions

Rotate a particle on collision? 0 Answers

Call OnTriggerEnter with a trigger particle? 0 Answers

OnParticleCollision() problem 1 Answer

OnParticleCollision registering twice? 1 Answer

Getting particles from the same system to act differently with different objects? 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