I want to create bullet spread for my game I am currently working on. I tried following one tutorial, but it didn’t work.
The way bullets work on my game is they are always raycasted in the middle of the screen from an empty game object and I want to create random bullet spread from that game object, but the question is how do I do it?
private void Fire(){
if (firetimer < firerate || CurrentBullets <= 0 || IsReload )
return;
RaycastHit hit;
if (Physics.Raycast (ShootPoint.position, ShootPoint.forward, out hit, range)) {
Debug.Log (hit.transform.name + "found");
GameObject hitParticlesEffect = Instantiate (HitParticles, hit.point, Quaternion.FromToRotation (Vector3.up, hit.normal));
hitParticlesEffect.transform.SetParent (hit.transform);
//Spawning both hit particles and bullet holes and setting their parents to whatever the ray cast hit
GameObject BulletObjectEffect = Instantiate (BulletObject, hit.point, Quaternion.FromToRotation (Vector3.forward, hit.normal));
BulletObjectEffect.transform.SetParent (hit.transform);
Destroy (BulletObjectEffect, 2f);
Destroy (hitParticlesEffect, 1f);
if (hit.transform.GetComponent<EnemyHealth> ()) {
hit.transform.GetComponent<EnemyHealth> ().ApplyDamage (damage + ArmorPenetration);
}
}