- Home /
I am trying to implement a magnetic field with particle system...
Though I managed to implement it with random objects( I expanded their collider, made it a trigger and transformed the objects), I can not find how to trigger the particles, since there is not an onTrigger option (there is also not an option where you can expand the collider of the particles and make it a trigger)
Answer by Mischa · Jul 07, 2015 at 09:15 PM
I'm not exactly sure what you want to achieve but I once wrote a particle attractor whitch attracts particles to a specific point. The class looks like this, maybe you can use something of it. It basically grabs the particles of a particle system and then manually changes their position based on their lifetime.
using UnityEngine;
using System.Collections;
public class ParticleAttractor : MonoBehaviour {
[SerializeField]
private Transform _attractorTransform;
private ParticleSystem _particleSystem;
private ParticleSystem.Particle[] _particles = new ParticleSystem.Particle[1000];
public override void Start ()
{
_particleSystem = GetComponent<ParticleSystem> ();
}
public void LateUpdate()
{
if (particleSystem.isPlaying) {
int length = _particleSystem.GetParticles (_particles);
Vector3 attractorPosition = _attractorTransform.position;
for (int i=0; i < length; i++) {
_particles [i].position = _particles [i].position + (attractorPosition - _particles [i].position) / (_particles [i].lifetime) * Time.deltaTime;
}
_particleSystem.SetParticles (_particles, length);
}
}
}
If this isn't working for you, make sure you set the particle system simulation space to "World"
Your answer
Follow this Question
Related Questions
particle systems' physics heavily depends on framerate?? 1 Answer
Change particle bounce relative to the speed of the GameObject colliding with them? 1 Answer
Can Particle System ignore a given collider? 3 Answers
Particle collisions without physics force 1 Answer
How to change a simple snow particle FX to generate a speed effect? 1 Answer