I have a problem in Unity3D and I’m afraid Unity doesn’t offer a solution to this.
My scene has a Particle System parented to a spaceship. This spaceship moves around, and the particles must move around with the spaceship. The solution to this would be easy; make it simulate in local space.
Now comes the twist: The Particle System itself moves around while being parented to the spaceship. The particle system follows waypoints along the hull of the ship, emitting particles on the way. This creates a visual ‘path’ between the waypoints.
When I use Local Space: The particles use the local space of the Particle System which is moving around. This means that all the particles will be put together in 1 point, which moves along over the path. No visual path created.
When I use World Space: The particles drop off the moving Particle System and create a visual path. However, when the ship begins to move, the particles are left behind.
The solution: To use the Local Space of the Spaceship, instead of the Local Space of the Particle System. Unity3D doens’t have any way to do this, though, which I find really disappointing.
I’m hoping someone on the forums has encountered this problem before, and perhaps has a solution for this. I have an idea, but don’t know if it will work.
I would have made the particle system a child of an invisible parent game object. That way the parent can follow whatever path you want and then each update just set the particle system rotation to that of the ship.
Sorry to bump an old thread, but I had the same issue and wanted to share the solution code.
Click for code
using UnityEngine;
//This will allow us to have the the particle system work in the local space of our parent object.
[RequireComponent(typeof(ParticleSystem))]
public class ParticlesLocalWorldSpace : MonoBehaviour
{
new ParticleSystem particleSystem;
ParticleSystem.Particle[] particleBuffer = new ParticleSystem.Particle[100];
Vector3 previousParentPosition;
void Awake()
{
particleSystem = GetComponent<ParticleSystem>();
particleSystem.simulationSpace = ParticleSystemSimulationSpace.World;
}
void LateUpdate()
{
int numParticlesAlive = particleSystem.GetParticles(particleBuffer);
Vector3 parentMovement = transform.parent.position - previousParentPosition;
for(int i = 0; i < numParticlesAlive; i++)
{
particleBuffer[i].position += parentMovement;
}
particleSystem.SetParticles(particleBuffer, numParticlesAlive);
previousParentPosition = transform.parent.position;
}
}