Blood Particles not spawning in the correct spot when hitting an enemy

I’m making an FPS game with physical bullets and I wanted to add a blood spray where you hit an enemy. The effect works fine and it spawns upon hitting an enemy, the issue is it doesnt spawn where I hit the enemy, instead it spawns a few feet away from the enemy in the air. I’m not quiet sure how to fix this so any help is greatly appreciated. Attached below is the bullet script that causes the effect to proc.

 if (objectWeHit.gameObject.CompareTag("Enemy"))
    {
        print("hit a Enemy");
        objectWeHit.gameObject.GetComponent<Enemy>().TakeDamage(bulletDamage);
        CreateBloodSprayEffect(objectWeHit);
        
        
        Destroy(gameObject);
    }
}

private void CreateBloodSprayEffect(Collision objectWeHit)
{
    ContactPoint contact = objectWeHit.contacts[0];

    GameObject bloodSprayPrefab = Instantiate(
        GlobalReferences.Instance.bloodSprayEffect,                                                                                                                         
        contact.point,
        Quaternion.LookRotation(contact.normal)
        );

    bloodSprayPrefab.transform.SetParent(objectWeHit.gameObject.transform);
}`

Also attached is the global References singleton script.

public class GlobalReferences : MonoBehaviour
{
    public static GlobalReferences Instance {get; set; }

    public GameObject bloodSprayEffect;
    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }
    }
}

Possible the blood particle prefab has a non-zero transform position?

2 Likes

you got it! I set the prefab to have a position of 0, but forgot to put the actual particle effect at 0. Thank you for the help again! Are you working on any projects yourself?

Great, you’re welcome! I work on a Unity game as my job and then I work on my own Unity project at home lol.

1 Like