- Home /
How do I make instantiated particles inherit Transform movement from their parent object?
I am using the Unity particle system to pop coins when I pick them up, but I pick them up in motion. I want the particles to fully inherit their parent object's transform. How do I do this?
Answer by Cherno · Apr 18, 2016 at 02:27 PM
Set the Particle System's Simulation space to local.
Actually, I want to set it to world, but either way I misspoke in the original post. I am using a particle generator from Unity's standard assets, but apparently that doesn't use particle system at all, making it hard to figure out how to make it "world".
Disregard the answer then as it doesn' apply to the question you are now asking. What exactly do you mean by "inherit their paren't transform"? Should they somehow be generated in local space relative to their parent, or should they inherit movement velocity? I don't know about this Particle Generator you speak of, How does it work? Does it just instantiate clones of prefabs?
I probably should have pasted this to begin with.
public class ExplosionPhysicsForce : $$anonymous$$onoBehaviour {
public float explosionForce = 4;
private IEnumerator Start()
{
// wait one frame because some explosions instantiate debris which should then
// be pushed by physics force
yield return null;
float multiplier = GetComponent<ParticleSystem$$anonymous$$ultiplier>().multiplier;
float r = 10*multiplier;
var cols = Physics.OverlapSphere(transform.position, r);
var rigidbodies = new List<Rigidbody>();
foreach (var col in cols)
{
if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody))
{
rigidbodies.Add(col.attachedRigidbody);
}
}
foreach (var rb in rigidbodies)
{
rb.AddExplosionForce(explosionForce*multiplier, transform.position, r, 1*multiplier, Force$$anonymous$$ode.Impulse);
}
}
}
This script is part of Unity's standard assets. There's also ParticleSystem$$anonymous$$ultiplier, but I don't think you need that, it just runs some math. Anyways, I drop this in a game object, I run it and boom, I get a flashing white particle. Problem is, that game object is moving, fast. And when the particle pops (and grows outward), the object continues moving, but the particle stays in place. It should be moving. I need some way to either
a. Add custom movement to the generated particle(s) or b. Force those generated particles to Space.World or some form of inherit movement.