- Home /
How to create a ParticleSystem whose particles orbit it independently?
Sure such a system can be created by having a empty GameObject, which has multiple GameObjects attached to it, each having its own ParticleSystem while also rotating their parent GameObjects. But having such a system with a 100 GameObjects as children has a noticeable impact on performance.
And I am starting to think the Shuriken particle system would be unable to do this.
it's not easy, there is a spiral/ galaxy particles generator somehwere on the net, i read it and found that shuriken was rather complicated.
You could certainly do it with a single particle system and some code. You would need to get and set properties on individual particles in the particles array.
http://docs.unity3d.com/ScriptReference/ParticleSystem.Particle.html
In other words shur-i-can't isn't able to spawn particles at a radius and impart a angular force? Seems like a small requirement.
What do you mean by saying 'orbit independently'? If you want to rotate all particles around some point just rotate particle system and set it's simulation space to local.
@davidsirmons, shouldn't the angular force be relative to particle distance from the center of the particle system? If yes then robertbu's suggestion is the only way to do it, via scripting movement of each Particle.
@incorrect, as a placeholder, I am currently rotating the whole particle system. But I would like for each particle to be rotating around the particle system's center independently. "simulation space" is not the issue.
Answer by Julian_Nementic · Oct 16, 2016 at 04:23 PM
This is old, but for guys who came along to find an anwer. I wrote a small script you just need to attach to the Particle System and than all Particles orbit around its center or to a position given by a transform in the inspector. Keep in mind that the ParticleSimulationSpace has a huge inpact of the Behavior.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(ParticleSystem))]
public class ParticlesOrbit : MonoBehaviour {
ParticleSystem m_System;
ParticleSystem.Particle[] m_Particles;
[Header("Keep in mind that this script works only in Playmode")]
[Tooltip("Make sure to set Particle Simulation Space to world. Otherwise it uses only the center of the Particle System to Orbit.")]
[SerializeField]
Transform CenterOfGravity;
public float strength = 1.0f;
void Start()
{
InitializeIfNeeded();
if (CenterOfGravity == null)
CenterOfGravity = transform;
if (m_System.simulationSpace == ParticleSystemSimulationSpace.Local && CenterOfGravity != null)
{
Debug.LogWarning("You can only use the Center of gravity variable if the ParticleSystemSimulationSpace is set to World. Now its using the center of the ParticleSystem.", this);
}
}
private void LateUpdate()
{
// GetParticles is allocation free because we reuse the m_Particles buffer between updates
int numParticlesAlive = m_System.GetParticles(m_Particles);
// Change only the particles that are alive
for (int i = 0; i < numParticlesAlive; i++)
{
Vector3 gravitation = new Vector3(0, 0, 0);
if (m_System.simulationSpace == ParticleSystemSimulationSpace.World)
{
gravitation = CenterOfGravity.position - m_Particles[i].position;
}
else
{
gravitation = Vector3.zero - m_Particles[i].position;
}
Vector3 normalizedGravitation = Vector3.Normalize(gravitation);
m_Particles[i].velocity += normalizedGravitation * strength;
}
// Apply the particle changes to the particle system
m_System.SetParticles(m_Particles, numParticlesAlive);
}
void InitializeIfNeeded()
{
if (m_System == null)
m_System = GetComponent<ParticleSystem>();
if (m_Particles == null || m_Particles.Length < m_System.maxParticles)
m_Particles = new ParticleSystem.Particle[m_System.maxParticles];
}
}
Cheers,
Julian
@joellehoelle - Thanks a bunch! This script was very helpful!
Your answer
Follow this Question
Related Questions
How to generate particles from an animated character? 0 Answers
Grass system? 2 Answers
Multiple particle systems or UV animation? (performance) 2 Answers
Prewarm Legacy Particles 0 Answers
Is shuriken well performing on iDevices? (iPhone, iPad) 1 Answer