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).
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.