Raycasting rotated in build

I’m running my game at the same 1440x900 resolution in both final build and editor, but when I build my game, any raycasts from the main camera are rotated slightly. and what’s worse, the rotation gets worse the further away the player is from 0,0,0 (world space).
8983147--1236172--upload_2023-4-30_12-28-50.png
bullets in the editor and close to where the player spawns are fine,


but bullets shot from further away are offset by a ton.

red is where the player spawns, and black is where I’ve seen it most often/exaggerated

if (Input.GetMouseButton(0))
        {
            if(shoottimer == 0)
            {
                Vector3 dir = cam.transform.forward;
                if (lastshot < 20 && !Input.GetMouseButton(1))
                {
                    dir.x += UnityEngine.Random.Range((21 - lastshot) * -0.005f, (21 - lastshot) * 0.005f);
                    dir.y += UnityEngine.Random.Range((21 - lastshot) * -0.005f, (21 - lastshot) * 0.005f);
                    dir.z += UnityEngine.Random.Range((21 - lastshot) * -0.005f, (21 - lastshot) * 0.005f);
                }
                RaycastHit hit;
                shoottimer = 15;
                lastshot = 0;
                Debug.Log("fired shot");
                shootaudio.Play();
                if (Physics.Raycast(cam.transform.position, dir, out hit, Mathf.Infinity))
                {
                    Debug.DrawRay(transform.position, dir * hit.distance, Color.yellow, 5000);
                    if (hit.collider.tag == "enemy")
                    {
                        hit.collider.gameObject.GetComponent<Health>().TakeDamage(25);
                        if(hit.collider.gameObject.GetComponent<Health>().health < 25)
                        {
                            //killed! goober
                            killaudio.Play();
                        }
                        Debug.Log("player hit bozo");
                    }
                    else
                    {
                        GameObject bh = Instantiate(bulletholeprefab, hit.point, Quaternion.FromToRotation(transform.up, hit.normal));
                        bh.transform.up = hit.normal;
                    }
                }

that’s the code that handles the raycasts and the instancing, and I don’t see anything there that’d change in build. time specific variables like shoottimer and lastshot are both updated in fixedupdate.

after removing the shooting innacurracy to see if that was the reason, I’ve found that the rotation flipflops between no rotation, (shooting forwards, what I want) and rotated towards the left,and towards the right. I still have no clue what’s happening though.
8983186--1236187--upload_2023-4-30_12-56-44.png8983186--1236190--upload_2023-4-30_12-56-53.png

I have no clue why, but moving the above code to lateUpdate() seemed to fix the issue.