Particle rotation always wrong on one axis when using Emit()

I’m trying to use the ParticleSystem to render decal and impact effects, but I’m unable to properly align the particle with the geometry in the world. There is always one axis where the particle is rotated incorrectly.

I’ve implemented a second version by spawing a quad gameobject for each decal and it just works as expected. However, I’m unable to implement the same thing with a particle system and I can’t figure out what I’m doing wrong.

I’ve recorded a video where I go over my test case, which is attached to this post. Any help is appreciated.

Thanks in advance!
PS: I’m using 2019.4.9f1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    [SerializeField] bool m_UseParticleSystem = default;
    [SerializeField] ParticleSystem m_ParticleSystem = default;
    [SerializeField] GameObject m_Quad = default;

    void Start()
    {
    }

    void Update()
    {
        if (!Input.GetButtonDown("Fire1"))
            return;

        RaycastHit hit;
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (!Physics.Raycast(ray, out hit))
            return;

        Debug.DrawLine(hit.point, hit.point + hit.normal * 0.25f, Color.blue, 1000);



        if (m_UseParticleSystem)
        {
            var position = hit.point + hit.normal * 0.01f;
            var rotation = Quaternion.LookRotation(hit.normal);// * Quaternion.AngleAxis(90, Vector3.Cross(hit.normal, Vector3.forward));

            var emit = new ParticleSystem.EmitParams();
            emit.position = position;
            emit.rotation3D = rotation.eulerAngles;
            emit.startColor = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
            m_ParticleSystem.Emit(emit, 1);
        }
        else
        {
            var position = hit.point + hit.normal * 0.01f;
            var rotation = Quaternion.LookRotation(hit.normal) * Quaternion.AngleAxis(180, Vector3.Cross(hit.normal, Vector3.forward));

            var quad = Instantiate<GameObject>(m_Quad);
            quad.transform.SetPositionAndRotation(position, rotation);
        }
    }
}

6404655–714855–UnityParticleSytemEmit.zip (40.5 KB)

It may be something to do with the (weird) default Transform we apply for particles (the 90 rotation on the Transform component)

It’s worth a bug report so we can check it.

1 Like

Thank you for the quick reply!

I just submitted bug-report:
(Case 1284152) 2019.4: Particle rotation always wrong on one axis when using Emit

I messed up the report a bit, I forgot to attach the video. However, I included a link to this forum thread. I hope the report passes QA :wink:

Just received an email, QA was able to reproduce the issue:

1 Like

Do you know if this gets fixed in 2019.4 or should I look for workarounds? I’m asking, because it blocks me.

We will take a look early next week and get back to you. Drop me a message on Tuesday afternoon/evening if you haven’t heard anything :slight_smile: (but I’ll try remember!)

1 Like

I had a little look at this.

For some reason we apply the negative of the rotation. It’s definitely some kind of bug, but the consequences of changing this code risks impacting lots of existing user content. So honestly we probably won’t try.

That said, I was able to make your script work by applying the same negation:

emit.rotation3D = -rotation.eulerAngles;

Let me know if that fixes things for you.

3 Likes

Thank you for the help. Yes, it fixes things for me, I just tested it. I’m glad it turned out that simple :slight_smile:

2 Likes