Back to list
verekia

camera-shake

by verekia

⚛️ React Three Fiber Game Dev Recipes

17🍴 0📅 Jan 22, 2026

SKILL.md


name: camera-shake description: Shake the camera when the player takes damage or on impacts for visual feedback.

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

  • Store rotation offsets in a module-level object for external triggering
  • Use exponential smoothing: (target - current) * (1 - Math.exp(-speed * dt))
  • Apply offsets to camera.rotation.x and camera.rotation.z
  • Call shake(intensity) from anywhere to trigger the effect

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
  • smooth-interpolation - Exponential smoothing formula details

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

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon