Search Unity

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

Discussion in 'General Graphics' started by Peter77, Oct 10, 2020.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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



    upload_2020-10-10_18-35-35.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     [SerializeField] bool m_UseParticleSystem = default;
    8.     [SerializeField] ParticleSystem m_ParticleSystem = default;
    9.     [SerializeField] GameObject m_Quad = default;
    10.  
    11.     void Start()
    12.     {
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.         if (!Input.GetButtonDown("Fire1"))
    18.             return;
    19.  
    20.         RaycastHit hit;
    21.         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    22.         if (!Physics.Raycast(ray, out hit))
    23.             return;
    24.  
    25.         Debug.DrawLine(hit.point, hit.point + hit.normal * 0.25f, Color.blue, 1000);
    26.  
    27.  
    28.  
    29.         if (m_UseParticleSystem)
    30.         {
    31.             var position = hit.point + hit.normal * 0.01f;
    32.             var rotation = Quaternion.LookRotation(hit.normal);// * Quaternion.AngleAxis(90, Vector3.Cross(hit.normal, Vector3.forward));
    33.  
    34.             var emit = new ParticleSystem.EmitParams();
    35.             emit.position = position;
    36.             emit.rotation3D = rotation.eulerAngles;
    37.             emit.startColor = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
    38.             m_ParticleSystem.Emit(emit, 1);
    39.         }
    40.         else
    41.         {
    42.             var position = hit.point + hit.normal * 0.01f;
    43.             var rotation = Quaternion.LookRotation(hit.normal) * Quaternion.AngleAxis(180, Vector3.Cross(hit.normal, Vector3.forward));
    44.  
    45.             var quad = Instantiate<GameObject>(m_Quad);
    46.             quad.transform.SetPositionAndRotation(position, rotation);
    47.         }
    48.     }
    49. }
    50.  
     

    Attached Files:

  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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.
     
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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 ;)
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    richardkettlewell likes this.
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Do you know if this gets fixed in 2019.4 or should I look for workarounds? I'm asking, because it blocks me.
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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 :) (but I’ll try remember!)
     
    Peter77 likes this.
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    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:
    Code (CSharp):
    1. emit.rotation3D = -rotation.eulerAngles;
    Let me know if that fixes things for you.
     
    konurhan, Peter77 and karl_jones like this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Thank you for the help. Yes, it fixes things for me, I just tested it. I'm glad it turned out that simple :)
     
    konurhan and richardkettlewell like this.