Camera shake doesnt work

For a scene, I want a static camera to shake a little bit. The code so far looks like this:

var CameraShake = pc.createScript('cameraShake');

CameraShake.attributes.add('intensity', { type: 'number', default: 0.5, title: 'Intensity' });
CameraShake.attributes.add('amplitude', { type: 'number', default: 0.2, title: 'Amplitude' });

CameraShake.prototype.initialize = function() {
    this.originalRotation = this.entity.getLocalRotation().clone();
    this.frequency = 20; // Adjust frequency for smoother motion
};

CameraShake.prototype.update = function(dt) {
    var xOffset = Math.sin(pc.time * this.frequency) * this.intensity * this.amplitude;
    var yOffset = Math.cos(pc.time * this.frequency) * this.intensity * this.amplitude;
    var zOffset = Math.sin(pc.time * this.frequency * 0.5) * this.intensity * this.amplitude; // Adjust frequency for z-axis rotation
    var rotation = this.originalRotation.clone().mul(pc.Quat().setFromEulerAngles(xOffset, yOffset, zOffset));
    this.entity.setLocalRotation(rotation);
};

BUT, as always, this doesn’t want to work. My screen looks completely black when using the script on the camera.

So, how do I fix this?

Thx in advance

Hi @SayHiToMePls!

I have no idea what could be wrong with your script, but the example project below includes a script for camera shake.

https://playcanvas.com/project/439297/overview/explosion-particle-effect