- Home /
Detecting Particle Collisions
Is it possible to detect where a stream of particles is colliding? I don't need the particles to bounce or anything crazy like that. I just need to know if it's intersecting a mesh. Is that within the range of Unity's capabilities?
Answer by sulas · Jan 27, 2010 at 07:31 PM
I haven't tried this pefore, but thought of doing something like that for a flamethrower. Check this out, it might help:
http://unity3d.com/support/documentation/Components/class-WorldParticleCollider.html
Answer by Ashkan_gc · Jan 27, 2010 at 08:20 PM
there is a component called particle collider that you can use to make particles lose energy or bounce or ... when colliding with other particles. there is a check box (bool value) in this component called SendCollisionMessage that if you check it a OnParticleCollision event will be called in all scripts attached to the GameObject containing the particle collider and the GameObject that particles collided with. so you can use this function in your mesh object and do what you want when particles collide with you. as you can see in the sample of documentation you can see the object that you collide with in the passed argument.
I should add that I'll be developing on iPhone. The goal is to have a narrow stream of water. Would message sending incur too high a load on the iPhone platform?
you can test it for yourself. it's depending on many factors. try to keep the code inside message lightweight and you'll be good to go. i don't have any experience in iphone development.
Answer by AD110 · Jan 17, 2017 at 02:43 PM
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Example : MonoBehaviour
{
public ParticleSystem.Particle[] ParticleList;
private ParticleSystem m_particleSystem;
private GameObject character;
int Score = 0;
void Start()
{
character = GameObject.FindGameObjectWithTag ("Iz");
m_particleSystem = GetComponent<ParticleSystem> ();
}
void LateUpdate ()
{
//This list will be used to store each particle that is alive
ParticleList = new ParticleSystem.Particle[m_particleSystem.particleCount];
//storing particles into a list
m_particleSystem.GetParticles (ParticleList);
// Change only the particles that are alive
for (int z = 0; z < GetComponent<ParticleSystem> ().particleCount; z++)
{
//getting the position of the player and the particle
Vector3 dis = ParticleList [z].position - character.transform.position;
//if it is near
if(dis.magnitude <= 5)
{
//destroy the particle
ParticleList [z].lifetime = 0;
//add score
Score++;
}
}
// Apply the particle changes to the particle system
m_particleSystem.SetParticles (ParticleList, m_particleSystem.particleCount);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612035014im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inconsistent Particle Collision detection 0 Answers
Particles collision Stopped working after a while 0 Answers
Why is ParticleCollider's intersection always zero? 1 Answer
HELP!! OnCollisionEnter is not working when i built it out on IPHONE! 0 Answers
Why do my first few collectable/powerup collisions cause lag but not later ones? 1 Answer