Showing posts with label Juice. Show all posts
Showing posts with label Juice. Show all posts

Wednesday, November 14, 2018

Camera Shake

These are notes made while watching this GDC talk.

General Information

  • Use a trauma variable that has a range of (0,1)
  • Factors like damage or stress adds to the trauma variable
  • The trauma variable decreases linearly overtime
  • Set the camera shake amount equal to trauma² or trauma³
  • This means that the camera shake and trauma variable are not linearly proportional
  • This creates a spring and damper effect that feels right for the player
  • It also allows the player to perceive how its escalating

Translational VS Rotational

2D

  • Rotational is okay
  • Translational is great
  • But Translational + Rotational is awesome

3D

  • Rotational is awesome
  • Translational is lame
N.B. Translational in 3D can also cause clipping with the environment.

VR

DON'T DO IT!!!

Implementations

In both implementations a second camera is used to do the camera shake effect, this means that the original camera is preserved. Also all angles used are eular angles.


2D

angle = maxAngle * shake * Random.Range(-1, 1);
offsetX = maxOffset * shake * Random.Range(-1, 1);
offsetY = maxOffset * shake * Random.Range(-1, 1);

shakyCam.angle = cam.angle + angle;
shakyCam.center = cam.center + Vector2(offsetX, offsetY);


3D

yaw = maxYaw * shake * Random.Range(-1, 1);
pitch = maxPitch * shake * Random.Range(-1, 1);
roll = maxRoll * shake * Random.Range(-1, 1);

shakyCam.rotation = cam.rotation + Vector3(pitch, yaw, roll);

If you want translational as well in 3D then include:
offsetX = maxOffset * shake * Random.Range(-1, 1);
offsetY = maxOffset * shake * Random.Range(-1, 1);
offsetZ = maxOffset * shake * Random.Range(-1, 1);

shakyCam.center = cam.center + Vector3(offsetX, offsetY, offsetZ);


3D using Perlin Noise

yaw = maxYaw * shake * GetPerlinNoise(seed, deltaTime, ...);
pitch = maxPitch * shake * GetPerlinNoise(seed + 1, deltaTime, ...);
roll = maxRoll * shake * GetPerlinNoise(seed + 2, deltaTime, ...);

shakyCam.rotation = cam.rotation + Vector3(pitch, yaw, roll);

If you want translational as well in 3D then include:
offsetX = maxOffset * shake * GetPerlinNoise(seed + 3, deltaTime, ...);
offsetY = maxOffset * shake * GetPerlinNoise(seed + 4, deltaTime, ...);
offsetZ = maxOffset * shake * GetPerlinNoise(seed + 5, deltaTime, ...);

shakyCam.center = cam.center + Vector3(offsetX, offsetY, offsetZ);

Random VS Smoothed Noise (Such as Perlin Noise)

  • Smoothed noise feels better
  • Smoothed noise automatically works with pause and slow motion due to use of deltaTime
  • Smoothed noise has adjustable frequency
  • Smoothed noise is more easily reproducible on replays