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);
}
}
}