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?