Accuracy not working properly

Here is my raycast gun accuracy script:

        Vector3 direction = transform.rotation.eulerAngles;
        direction.y += Random.Range(-accuracy, accuracy);

        ray.origin = transform.position;
        ray.direction = direction;

What is wrong with it? I cannot wrap my head around it!

Hey Calmcarrots!

I made two versions of a function that can use inaccuracy ranges, either for custom vectors or a transform!

Here you go:

//Calculate with custom vectors
	Vector3 CalcAccuracy(Vector3 Forward, Vector3 Right, Vector3 Up, float pAccuracy)
	{
		//Get the error range
		float RandAcc = Random.Range(-pAccuracy, pAccuracy)/10;
		//Calc left and right error range
		Vector3 newDir = Forward + Right * RandAcc;

		//Optional - Recalc error range for up and down
		RandAcc = Random.Range(-pAccuracy, pAccuracy)/10;
		//Calc up and down error range
		newDir = newDir + Up * RandAcc;

		return newDir;
	}

	//Calculate with a transform
	Vector3 CalcAccuracy(Transform pTrans, float pAccuracy)
	{
		//Get the error range
		float RandAcc = Random.Range(-pAccuracy, pAccuracy)/10;
		//Calc left and right error range
		Vector3 newDir = pTrans.forward + pTrans.right * RandAcc;
		
		//Optional - Recalc error range for up and down
		RandAcc = Random.Range(-pAccuracy, pAccuracy)/10;
		//Calc up and down error range
		newDir = newDir + pTrans.up * RandAcc;
		
		return newDir;
	}

You can remove the second half of the functions if you only want a left to right update.

Hope this help!

-Peace