Particles spawn far away from transform

So the way i have the script set up its suppose to spawn at the target transform but instead its spawning way off in the distance.

    void isattacker()
    {
        if (isattackingnow == true)
        {

            if (Input.GetMouseButtonDown(0) && GetComponent<Battler>().attacktimer.fillAmount == 1)
            {
                hitsound.Play();
                Instantiate(hit, target);
                target.GetComponent<Battler>().takedamage(attackDamage);
                target.GetComponent<EnemyControl>().takedamage(attackDamage);

            }
        }
    }

Currently this is the Instantiate implementation you’re using:
public static Object Instantiate(Object original, Transform parent);

As you can see, passing a Transform as the second parameter makes that Transform the parent, but does not set the position at all. If your prefab position is not zeroed out, it will spawn off center.

Try using “Instantiate(hit, target.position)”.
or “Instantiate(hit, target, false)” and zero out the prefab position.

thanks works perfectly!

1 Like