I want to use collision with particle system in 2D. but it didn’t work out.
I think that because there is no OnParticleCollision2D callback. Of course it works in 3D.
any one ever think about this? If so please please help me!!!
I want to use collision with particle system in 2D. but it didn’t work out.
I think that because there is no OnParticleCollision2D callback. Of course it works in 3D.
any one ever think about this? If so please please help me!!!
This is not true anymore
You can use Particel System that Collide with 2D Sprites
For that you need to go in the Particel tap to Collision
and there Change the Collision Mode from 3D to 2D
I Hope i Could help Someone
Have a Nice Day and keep Coding
Particles don’t collide with 2D Colliders.
If you think about it, it would be hard to decide what should happen anyway, as 2D Colliders live on a constant z-plane and particles move in 3D, so they would rarely hit the exact edge of a 2D collider and more likely move in from or behind the collider.
If you really need this, you can still create BoxColliders etc. in a 2D Game.
thanks I gave up using particle collision in 2d lol
I know this is a little old but I did figure out a really simple way to do this.
In Unity on the particle system just make sure the Triggers section is checked and attach this script to the same GameObject
using UnityEngine;
public class Test : MonoBehaviour
{
// The particle System
private ParticleSystem sys;
// Array of alive particles
private ParticleSystem.Particle[] aliveParticles;
// The 2d collider that we want to collide with
// the particle system
private BoxCollider2D boxCollider;
// Called when any particle meets the condition
// of the trigger section of the particle system
private void OnParticleTrigger()
{
// Check to see what needs to be initialized
InitializeIfNeeded();
// Get the particles that are currently alive
// and store them in the array
sys.GetParticles(aliveParticles);
// Loop through the particles in the array
foreach (ParticleSystem.Particle particle in aliveParticles)
{
// Check for collision
if (boxCollider.bounds.Intersects(new Bounds(particle.position, particle.GetCurrentSize3D(sys))))
{
Debug.Log("Success");
}
}
}
// Initialize the variables only once
private void InitializeIfNeeded()
{
// Get the 2d trigger collider from the GameObject
// This can be done in several different ways, I chose
// to add a tag and find it that way
if (boxCollider == null)
boxCollider = GameObject.FindGameObjectWithTag("HurtBox").GetComponent<BoxCollider2D>();
// Get the particle system we want to collide with and
// add the 2d trigger collider to it
if (sys == null)
{
sys = GetComponent<ParticleSystem>();
sys.trigger.SetCollider(0, boxCollider);
}
// Initialize the array that holds the alive particles
if (aliveParticles == null)
aliveParticles = new ParticleSystem.Particle [sys.main.maxParticles];
}
}