title: Unity - Tricky Particle Collisions
body: <p>I am making a prototype for my 2D game. It consists of a ball that launches missiles that are aimed to explode where the user clicks. The explosion of the missile releases particles, which hit the ball and exert a force on the ball. Here is a <a href="https://youtu.be/xp8CznTG48I" rel="nofollow noreferrer">video</a>.</p>
  
  <p>I used a standard particle system with the Collision module activated. Then attached this script to the particle systems created be each explosion:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class particleInteraction : MonoBehaviour {
  
      //PS Variables
      ParticleSystem myPS;
      public List&lt;ParticleCollisionEvent&gt; particleCollisions = new List&lt;ParticleCollisionEvent&gt;();
  
      //Physics variables
      public float effect;    
  
  
      // Use this for initialization
      void Start () {
          myPS = GetComponent&lt;ParticleSystem&gt;();
      }
  
  
      void OnParticleCollision (GameObject other)
      {
  
          //Checking if the hit object is indeed the ball
          if (other.tag.Equals("Player"))
          {
              Rigidbody2D hitObject = other.GetComponent&lt;Rigidbody2D&gt;();
  
              //Getting the number of particles hat hit the ball
              int noOfCollisions = myPS.GetCollisionEvents(other, particleCollisions);
  
              Vector3 particleDirection = new Vector2(0,0); //The overall velocity of all the particles that collided
  
              //Iterating through all the collisions and adding their vectors
              for (int i = 0; i &lt; noOfCollisions; i++)
              {
                  particleDirection += particleCollisions[i].velocity;
              }
  
              //Applying the resultant force
              hitObject.AddForce(particleDirection.normalized * effect * noOfCollisions);
          }
      }
  
  }
  </code></pre>
  
  <p>This mostly works, however it causes a problem. The missile are designed to explode when they hit the walls too, so when the ball is on a wall I expect a missile aimed at the wall to push the ball off of it. However, the ball simply jerks away from the wall in the next frame (can be seen in the video). I believe this is because of the colliders on the particles instantiating inside of the ball's collider. This causes the physics engine to immediately move the ball away in the next scene.
  So I tried using OnParticleTrigger, however I realized that Unity doesn't provide info on the gameobject affected in particle triggers, so I cannot affect the ball.</p>
  
  <p>Could anyone help me find a way to make this work? <em>I want to avoid the jerky movement caused by the intersecting colliders, or maybe use a better method expressing the missile explosions.</em></p>