Shake camera effect is not visible through the headset

Hello, I have an issue with a camera effect that I am trying to achieve in my game. I am looking to have a camera screen shake which works all fine and even is working in the editor while I have my headset one.
So the camera view in the editor actually shows the XR Rig camera shaking back and forth but I cannot see this effect appear in the headset. I would be really thankful if someone can help me out with this. Here is the code I have used for the effect:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shake : MonoBehaviour
{
    public float duration = 1f;
    public float delay = 0f;
    public bool shake = false;
    public AnimationCurve curve;
    // Update is called once per frame
    void Update()
    {
        if (shake)
        {
            shake = false;
            StartCoroutine(Shaking());
        }
    }

    IEnumerator Shaking()
    {
        Vector3 startPos = transform.localPosition;
        float elapsedTime = 0f;
        while(elapsedTime < duration)
        {
            elapsedTime += Time.deltaTime;
            float strength = curve.Evaluate(elapsedTime / duration);
            transform.localPosition = startPos + Random.insideUnitSphere * strength/10;
            yield return null;
        }
        transform.position = startPos;
    }

    void startShake()
    {
        shake = true;
    }

    public void shakeCam(float time)
    {
        delay = 0f;
        duration = time;
        Invoke("startShake", 0);
    }

    public void delayedShakeCam(float delay, float time)
    {
        duration = time;
        this.delay = delay;
        Invoke("startShake", delay);
    }
}

Please edit your post to use code-tags when posting code rather than plain text.

Thanks.

1 Like

try moving the camera parent transform, i’d guess camera position is overwritten from XR tracking?

but i wouldn’t add camera shake on VR headsets, might be quite uncomfortable…

1 Like