Camera shake

From verekia/r3f-gamedev · View interactive version

Camera shake is an AI agent skill from the GitHub repository verekia/r3f-gamedev. Shake the camera when the player takes damage or on impacts for visual feedback.

How to use this skill

Skill file

Camera Shake

Shake the camera when the player takes damage or on impacts for visual feedback.

Technique

Instantly offset the camera's rotation on X (pitch) and Z (roll) axes, then smoothly return to the base rotation using exponential decay in useFrame.

Key Concepts

Usage

const shake = (intensity = 0.05) => {
  rotationOffset.x = (Math.random() - 0.5) * intensity
  rotationOffset.z = (Math.random() - 0.5) * intensity
}

// In useFrame:
rotationOffset.x += addSmoothExp(rotationOffset.x, 0, 10, delta)
camera.rotation.x = rotationOffset.x

Related Skills


This skill is part of verekia's **r3f-gamedev**.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.