Controlling particles hit point with code?

When I fire a weapon in my game there’s bullet spread. I shoot “bullets” wity Raycast… When I shoot I activate a muzzle flash, and on this muzzle flash PS I’ve added one particle that flies away with high speed leaving a trail behind (to simulate a bullet flying through the air). Now, this bullet trail goes straight forward each time; not ending up where my raycast bullets end up - making it look a bit weird…

Can I control that particular particle to end up where the raycast bullets end up (hit.point)? If so, how?
Darn, I hope you guys understand what I mean:smile:

private void Update()
    {
        if (!canShoot)
            return;

        ellapsedTime += Time.deltaTime;

        if(controller.m_Input.x != 0 || controller.m_Input.y != 0)
        {
            bulletSpread = (normalSpread * spreadMultiplierWhenMoving);
        } else
        {
            bulletSpread = normalSpread;
        }

        if (Input.GetButton("Fire1") && ellapsedTime > shotCooldown)
        {
            Vector3 spreadDirection = firePosition.forward;

            ellapsedTime = 0f;
            CmdFireShot(firePosition.position, spreadDirection + Random.insideUnitSphere * bulletSpread);
        }
    }

    [Command]
    void CmdFireShot(Vector3 origin, Vector3 direction)
    {
        Ray ray = new Ray(origin, direction);
        Debug.DrawRay(ray.origin, ray.direction * 3f, Color.red);

        bool result = Physics.Raycast(ray, out hit, 150f);
        bool hitEnemy = false;

        if(result)
        {
            PlayerHealth enemy = hit.transform.GetComponent<PlayerHealth>();

            if(enemy != null)
            {
                hitEnemy = true;
                bool wasKillShot = enemy.TakeDamage(transform.position, Random.Range(bulletDamage.x, bulletDamage.y));
                if (wasKillShot)
                    score++;
            } else
            {
                hitEnemy = false;
            }
        }

I ofc understand that I need to referense that Particle Effect, but… then what? :slight_smile:

Oh yeah; forgot to mention… This needs to be done over network. I have tried creating a empty GameObject with a Trail Render component as a prefab = it needs to be instantiated with NetworkServer.Spawn() and the position of the prefab needs to be synced over the network which is impossible since it would be moving so fast; so the best solution would be to make this a part of the particle system of the muzzle flash and control where that BulletTrail particle ends up…

If it was a Single player offline game, the prefab would work perfectly thou…