- Home /
Changing particles in particle system from local space of skinned character mesh to world space (unattached)
Hi,
First off I'm still new to Unity, C# and Javascript - come from a Python/C++/Maya Scripting background. Not sure if this should be in the forum instead, but anyway.
I'm currently working on a project in which I need to have particles attached to the vertices of a skinned (animated) mesh when they are created, but then they need to be in world space for every frame after that (end result will be sort of a ghosting effect!)
I currently have it so that the mesh for the skinned character controller is being baked out each frame, its vertices are put into an array and these positions are passed to particles in a particle system (which is attached in the same place as the script but has been made inert), which is set every frame.
So the particles follow the animated mesh around fine (there's a tiny bit of lag but I don't mind that for now). The only problem is the script is a component under the Bip001 Pelvis part of the default 3rd Person Controller, firstly so it can access the Skinned Mesh Renderer (needed for baking the mesh each frame) and secondly so it actually follows the position and orientation of the character animation. I tried putting the script into its own empty GameObject and accessing the necessary objects and components from there but it only introduced more problems! Is there any easy way to make particles that are instanced from a script parented under the character stop following it after they are spawned, essentially??
I know this is a fairly complex/confusing setup but any advice would be great. (Sorry for the crude image too! - and ignore the other Emitter, that was for testing)
My other issue is that I think the particles are ignoring my assignment of attributes such as the size and instead go by the inert Particle System, when I both create them and update them based on the changing mesh - no idea why this is. Do the attributes for the Particle System Component in the Inspector take precedence over scripts?
private void CreatePoints (Vector3[] verts, ParticleSystem.Particle[] points)
{
for (int i = 0; i < resolution; i++)
{
points[i].position = verts[i];
points[i].color = new Color(1f, 1f, 1f);
points[i].size = 100f;
points[i].lifetime = 1;
}
}
public void SetPoints (Vector3[] verts, ParticleSystem.Particle[] points)
{
Debug.Log("Length of verts array");
Debug.Log(verts.Length);
for (int ii = 0; ii < resolution; ii++)
{
points[ii].position = verts[ii];
points[ii].color = new Color(1f, 1f, 1f);
points[ii].size = 1f;
points[ii].lifetime = 1;
}
}
Update: I've moved the script and particle system into a separate empty object but have the problem that when I position the particles onto the Bip001 Pelvis of the Character Controller, the mesh is at the wrong angle. The pelvis part is at the wrong orientation when you look at it in the Assets folder too! Does anyone know why this is?
FURTHER UPDATE: All sorted (for now!) so no help needed. Can I delete questions?
Your answer
Follow this Question
Related Questions
Can you still not change the Velocity of spawned particles? 2 Answers
Optimizing the Performance of a Large Particle System 2 Answers
how to rotate particles in a particle system 1 Answer
how to use the unity3d 5.3 particle system shape of skinned mesh renderer? 2 Answers
Mesh Particle Emitter & Animation 0 Answers