I am making a fps in unity and i have implemented weapon accuracy by adding random number with the range of my “bulletSpread” to the camera.transform.forward. It works perfectly however I want the first shot from a weapon to be 100% accurate (or close to it). Here is the code for my raycast.
Also for some reason the debug.drawray is not working
rayDirection = fpsCam.transform.forward;
rayDirection.x += Random.Range(-bulletSpread, bulletSpread);
rayDirection.y += Random.Range(-bulletSpread, bulletSpread);
rayDirection.z += Random.Range(-bulletSpread, bulletSpread);
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, rayDirection, out hit, range))
{
Debug.Log(hit.transform.name);
Debug.DrawRay(fpsCam.transform.position, rayDirection);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGo, .1f);
}