I have a script setup to shake the X/Y position of an orthographic camera to simulate a screen shaking effect. It looks great in the editor but once I push a build to mobile I see a white border around the edges of the screen during the shake effect.
I have no idea what to even check, I have no white backgrounds or skyboxes. Has anyone run into this before?
This is pretty vague; What Unity version? Which target platform? What kind of camera settings? What kind of scene setup? Screen captures? Video footage? It could be just user generated situation or something else.
2017.3.3f1, Android, Default Orthographic camera. Base scene with a background, orthographic camera is well within the bounds of the background. I’m trying to figure out how to record a video on my Note9, Gametools won’t pop up for some reason.
Tossed a large black image behind all of the other elements and I’m still seeing a white outline, I exaggerated the shake magnitude and i’m seeing artifacting from other parts of the screen.
This is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraShakeScript : MonoBehaviour
{
Rect initialViewport;
Camera mainCamera;
float shakeTime = 0.2f;
float shakeTimer = 0.0f;
float shakeMag = 0.0f;
// Start is called before the first frame update
void Start()
{
mainCamera = GetComponent<Camera>();
initialViewport = new Rect(mainCamera.rect);
}
// Update is called once per frame
void Update()
{
if(shakeTimer >= 0)
{
shakeTimer -= Time.deltaTime;
Shake();
}
else
{
mainCamera.rect = initialViewport;
}
}
public void Shake()
{
Rect tmpShake = new Rect(initialViewport.x + Random.Range(-shakeMag, shakeMag) * 0.15f,
initialViewport.y + Random.Range(-shakeMag, shakeMag) * 0.15f,
initialViewport.width, initialViewport.height);
mainCamera.rect = tmpShake;
}
public void ShakeCamera(float mag)
{
shakeMag = mag;
shakeTimer = shakeTime;
}
}
And here’s what it looks like when the shake hits:
Turns out I had my camera set to Screen Space instead of World Space, once I changed that over I was able to affect the Camera transform position instead of using the ViewRect, apparently it doesn’t like its bounds being set outside of the 0-1 Range, so that was causing the artifacting.