Search code examples
unity-game-enginerotationparticlesparticle-systemdecal

Unity3D - Rotate Decal Particle from ParticleSystem to Match Normal


I am trying to use a ParticleSystem for Decals as a cheap alternative but am unable to align the particles with all normal surfaces.

This is the nearest I've got that gets all axis correct except for an inverted x axis. (I can see it's the wrong way round on building windows)

if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit))
{
    Quaternion rot = Quaternion.LookRotation(hit.normal);

    ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams
    {
        position = hit.point + 0.01f * hit.normal,
        applyShapeToPosition = true,
        rotation3D = rot.eulerAngles
    };

    _particleSystem.Emit(emitParams, 1);
}

ParticleSystem Settings

ParticleSystem Settings

ParticleSystem Renderer Settings

ParticleSystem Renderer Settings

I have tried multiple methods over the past 24 hours and have now got myself lost even though it may be something simple.

Sorry about the image sizes - scaling them down messed with the text.

Edit: The editor and project settings are 2020.3.15F2 using URP.


Solution

  • I finally managed to figure it out and as no-one was able to answer I will add the solution in case it can help someone else.

    1: I inverted the hit.normal when gettting the rotation.

    if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit))
    {
        Quaternion rot = Quaternion.LookRotation(-hit.normal);
        ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams
        {
            position = hit.point + 0.01f * hit.normal,
            rotation3D = rot.eulerAngles
        };
    
        _bloodshotParticles.Emit(emitParams, 1);
    }
    

    2: Changed the render type from Billboard to Mesh with a Quad set.

    Renderer Fix/Edit