Instantiating Wound from Projectile Inconsistant

I’m simply trying to create a wound/bullet hole facing away from the normal, blood particles going outwards. It works 10 percent of the time and I don’t know what the problem is. I have a instantiated version of this which uses the camera forward position but would like to have it work with projectiles this time. I’ve already changed the rotation of the wound prefab to face outwards so no need to have it adjust in the code.

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

public class scr_BulletCollide : MonoBehaviour
{
    Rigidbody rb;
    public GameObject bloodPrefab;
    RaycastHit hit;
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    private void Update()
    {
        Debug.DrawRay(transform.position, transform.forward * .5f);
        transform.rotation = Quaternion.LookRotation(rb.velocity);
        Physics.Raycast(transform.position,transform.forward, out hit,.5f,512);
    }
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log(other.transform.tag);
        if(other.transform.tag != "Player")
        {
           
            Instantiate(bloodPrefab,hit.point,Quaternion.LookRotation(hit.normal));
            Destroy(this.gameObject);
           
        }
    }
}

An image to help visualize what the code is looking like. The bullet hole is in the correct rotation but it was instantiated at the hit point (of the main camera). I would like to replicate this with the bullet traveling.

GameObject bloodInstance = Instantiate(bloodPrefab);
bloodInstance.transform.position = hit.point;
bloodInstance.transform.forward = hit.normal;
// or use = -hit.normal, if you have backwards prefab

Also note that if it’s just not showing up sometimes at all (vs. improper rotation), it’s probably due to no offset from the surface (i.e. the decal and surface align exactly), so depth sorting is useless and it’s invisible because it’s been sorted behind the surface. So what you want to do is offset the position from the surface in the direction of the normal. If you don’t have the decal itself as a child GameObject inside your prefab slightly offset already, you can do this:

float offset = 0.1f; // exact offset up to you
bloodInstance.transform.position = hit.point + (hit.normal * offset);

Thanks for the response. I tried using the code above but still having issues. I did a Debug.Log and found out that the hit.point was showing up as vector3.zero. Not sure what the reason is because it does work 1/10 times.

It’s coming from this command.
bloodInstance.transform.forward = hit.normal

If it’s a MeshCollider, make sure it has the same mesh assigned to it as the MeshFilter

Is this in reference to the mesh/enemy being collided with or the blood prefab?

This command is the one that seems to be causing the error:
bloodInstance.transform.forward = hit.normal

6838103--795728--upload_2021-2-14_18-13-6.png

I increased the size of the projectile/collider by a substantial amount and its working properly. The problem is that bullets are much smaller than what I have currently.

The problem is still occurring much less than before but still getting the LookRotation viewing vector is zero still and it’s very random

Current Workaround:
I replaced the trigger and collider entirely. Instead I use the raycast hit.distance and have it activate once it is under .1f and extended the raycast distance to 10f.