Gun Recoil in Space C# (please help if your good with rotational stuff)

Hello my friends, the issue is, I have a spray pattern working but only when I am looking dead forward, If i turn around the spray pattern is inverted on the y axis, if I look up then it only sprays in one axis, same for down, left and right. The code used is the following" rayDirection = player.transform.forward + inaccuracyVector**
The rayDirection is used when raycasting to determine the desired direction, and the inaccuracyVector is just the coordinate of where i want the bullet to land. In my head, I’ve designed it so that the transform.forward is (0, 0, 0) so i can just add numbers on to it to make the spray pattern work, hence it works when looking forward. but for the life of me, i have no idea how to transfer this to work when looking in all directions. If anyone knows an answer that would be fantastic, thank you!

Try camera.transform.forward instead. That way its based off of the rotation of the camera rather than just your player object.