Search Unity

Rotating a subemitter

Discussion in 'General Graphics' started by GodlyGreedy, Jul 5, 2019.

  1. GodlyGreedy

    GodlyGreedy

    Joined:
    Apr 21, 2019
    Posts:
    10
    Hey!

    I've been fiddling with a particle effect that splits into multiple particles at the end of it's lifespan.

    when the parent particle system is not rotated at all we don't run into any problems and we get this effect:

    Parent rotation 0, 0, 0. Sub emitter rotation 90, 0, (90 - arc / 2). camera rotation 0, 0, 0.

    That's sort of what we're looking for. However, when I rotate the parent system to it's side we get this bullshit:


    Parent rotation 90, 0, -90. Sub emitter rotation (90, 0, 90 - arc / 2). camera rotation 90, 0, 0.

    I think the problem is that the circle shape of the sub emitter is rotating around an axis, which turns the rotation of the "prongs" at poles perpendicular to the axis, but not the ones on the axis. The emission points along the way appear to be partly rotated. I've tried all sorts of rotations for both the parent and the sub emitter, but nothing seems to work.

    The slight curve in the second picture is due to the gameobject following my mouse.

    In case it's of any use here's the script for creating the sub emitter:

    Code (CSharp):
    1.   void Start()
    2.     {
    3.  
    4.  
    5.         if (enableSub)
    6.         {
    7.             Material particleMaterial = subMaterial;
    8.             var subSystemGO = new GameObject("SubSystem");
    9.             var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>();
    10.             var subMain = subParticleSystem.main;
    11.             var subShape = subParticleSystem.shape;          
    12.             var subEmission = subParticleSystem.emission;
    13.             var subModule = particleLauncher.subEmitters;
    14.             var subMode = ParticleSystemShapeMultiModeValue.BurstSpread;
    15.  
    16.  
    17.             subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
    18.             subMain.startColor = Color.red;
    19.             subMain.startSize = subSize;
    20.             subMain.startSpeed = subSpeed;
    21.             subMain.startLifetime = subLifeTime;
    22.             subMain.simulationSpace = ParticleSystemSimulationSpace.World;          
    23.             subShape.shapeType = ParticleSystemShapeType.Circle;
    24.             subShape.arc = subArc;
    25.             subShape.arcMode = subMode;
    26.             subEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, subNumOfParticles) });
    27.  
    28.            
    29.             subSystemGO.transform.SetParent(playertransform.transform);
    30.             subSystemGO.transform.Rotate(90, 0, 90 - subArc / 2);
    31.             subModule.enabled = true;
    32.             subModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritColor);        
    33.         }
    Is there a way I can rotate the actual arc the subemitter particles are created from? Or maybe some other work around? Been stuck on this one for a hot minute.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    A guess, because it would take me more time to fully understand your setup: Set the transform inside the shape module of the subemitter instead of the subemitter gameobject?
     
  3. GodlyGreedy

    GodlyGreedy

    Joined:
    Apr 21, 2019
    Posts:
    10
    Hey, big thanks for your reply.

    right now I'm trying, relevant lines are 7, 27 and maybe 26:


    Code (CSharp):
    1.   if (enableSub)
    2.         {
    3.             Material particleMaterial = subMaterial;
    4.             var subSystemGO = new GameObject("SubSystem");
    5.             var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>();
    6.             var subMain = subParticleSystem.main;
    7.             var subShape = subParticleSystem.shape;           //setting the shapemodule variable
    8.             var subEmission = subParticleSystem.emission;
    9.             var subModule = particleLauncher.subEmitters;
    10.             var subMode = ParticleSystemShapeMultiModeValue.BurstSpread;
    11.            
    12.  
    13.  
    14.             subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial;
    15.             subMain.startColor = Color.red;
    16.             subMain.startSize = subSize;
    17.             subMain.startSpeed = subSpeed;
    18.             subMain.startLifetime = subLifeTime;
    19.             subMain.simulationSpace = ParticleSystemSimulationSpace.World;          
    20.             subShape.shapeType = ParticleSystemShapeType.Circle;
    21.             subShape.arc = subArc;
    22.             subShape.arcMode = subMode;
    23.             subEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, subNumOfParticles) });
    24.            
    25.            
    26.             subSystemGO.transform.SetParent(playertransform.transform);         // Parenting the GameObject
    27.             subShape.rotation = new Vector3(90, 0, 90 - subArc / 2);          //Setting the transform in the shapemodule
    28.             subModule.enabled = true;
    29.             subModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritColor);    
    I believe I'm rotating the shape module here. I've tried and failed using some sort of ParticleSystem.ShapeModule.rotation line, but I've led myself to believe that ParticleSystem.Shape does the same thing. When playing the scene the values are set in the shape module and not in the transform. Also, I can make changes in the transform and shape module with identical results. Rotating the object with the transform or the shape module around the z axis just turns the messed up prongs 90 degrees, from the x to the z axis.

    If there's any other relevant info I could provide, I'd be happy to. If ya'll just don't have the time for this, I can't blame you.

    Again, huge thanks for your reply.
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hey, so i looked at this a bit more. I'm not sure you need to rotate your sub-emitters at all. They automatically determine their rotation from the direction the parent particle is travelling in.

    EDIT: Ahh.. actually.. I just mocked this up myself and I'm seeing the same behaviour as you are. I'd say this looks like a bug. Could you report it please and reply here with the case number once you have it. Thanks!
     
    Last edited: Jul 8, 2019
  5. GodlyGreedy

    GodlyGreedy

    Joined:
    Apr 21, 2019
    Posts:
    10
    Hey, reported the bug. Case number is 1168251.

    Really didn't expect it to be a bug. Thought it'd be my spaghetti code.
     
    richardkettlewell likes this.