I am trying to set the starting rotation of a particle system via c# script so that the particles orientate with another object in the scene. My particle system 3d rotation is set as follows:

void UpdateParticleSystemRotation(Quaternion rotation)
        if(this.gameObject.GetComponent<ParticleSystem>() != null)
            var particleSystemMainModule = gameObject.GetComponent<ParticleSystem>().main;
            particleSystemMainModule.startRotationX = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.x);
            particleSystemMainModule.startRotationY = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.y);
            particleSystemMainModule.startRotationZ = new ParticleSystem.MinMaxCurve(rotation.eulerAngles.z);
            Debug.LogError("There was an error");

The rotation.eulerAngles.x/y/z values are coming through correctly, and by debugging in VS I can see that the values have been correctly assigned, as below:

Correctly assigning rotation.eulerAngles.x with the value of the rotation provided in the Quaternion parameter

However I observe that the particle system is not at all orientated with this X value, and the particle system is showing a completely different value:

Completely incorrect value observed in the editor and orientation of particle system

You can see from the screenshots above that a value of 74.5f becomes 4274.2f by the time it hits the particle system.

I have double checked that the type expected by the ParticleSystem.MinMaxCurve constructor is a float. I cannot understand why this is happening.

I would be very grateful if someone would be able to provide some clarification on this.

Many thanks in advance.

I should add, rotation seems completely random for any given input value, it doesn't follow any obvious rhyme or rhythm.

I am using Unity 2017.2.0f3


When in doubt, don't forget to read the docs:

public ParticleSystem.MinMaxCurve startRotationX;

The initial rotation of particles around the X axis when emitted.

Note that the value should be given in radians

So 74.5 radians converted to degrees for display in the editor is:

74.5 • 180° / π = 4268.5°

Which looks on par with what you're seeing in the inspector.

Dropping the scale of all your code-provided angles to a few multiples of π should make things behave much more sensibly.

Also remember that order matters when composing rotations, like the x, y, and z angles in Euler form, so take this into account when planning the angles you use to avoid surprises.

  • \$\begingroup\$ Ah! @DMGregory I think you might be onto something there...!! I got confused with the fact that the editor shows in degrees. I shall confirm this is correct when I get home tonight and accept your answer. Thank you kindly for your reply. \$\endgroup\$ – Ben Hayward May 17 '18 at 11:59
  • \$\begingroup\$ Please do not cross-post between StackExchange sites. We close questions when we spot that they've been cross-posted. Ask on just one site, whichever one you think is best suited to your problem. \$\endgroup\$ – DMGregory May 17 '18 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.