I'm working on an FPS game. I want to make a little bit of difference in shooting direction, only on the horizontal axis.
To do this, I wrote this code:
Temp_Shake_Horizontal.x = Random.Range(-0.1f, 0.1f);
if (Physics.Raycast(the_camera.position, the_camera.forward + Temp_Shake_Horizontal, out BulletDecal_Hit, Mathf.Infinity))
{
Quaternion HitRot = Quaternion.FromToRotation(Vector3.forward, BulletDecal_Hit.normal);
decals_Objs[decal_Index].transform.position = BulletDecal_Hit.point;
decals_Objs[decal_Index].transform.rotation = HitRot;
}
But I don't know why, when I rotate the camera, the result is changing!
Here is what it looks like when I face in one direction (this is the intended result):
But when I rotate the camera about 90 degrees to the left or right, the result is no horizontal variation: the bullets all line up in a vertical column.
Why does this happen, and how can I solve this issue? I want the result to always be like the first picture, with random variation side-to-side.