The ShakeComponent is designed to create a camera shake effect in a game. It randomly displaces the position and rotation of a node (presumably representing the camera) around the origin (0,0,0) coordinate. This effect adds visual impact and realism to certain game events, such as explosions, impacts, or intense moments.
How to Use
To use the ShakeComponent, you would typically attach it to a game object (like the main camera) that you want to shake.
Here’s how you might use its features:
- Time Scale (SetTimeScale and GetTimeScale): The timeScale_ parameter acts as a multiplier for the Perlin Noise argument. Adjusting this value changes the speed and intensity of the camera shake. Higher values result in faster and more intense shaking.
- Trauma (AddTrauma, SetTrauma, and GetTrauma): The trauma_ value represents the current intensity of the shake. You can increase it using AddTrauma or directly set it with SetTrauma. The component uses this value to determine how much to shake the camera.
- Trauma Power (SetTraumaPower and GetTraumaPower): The traumaPower_ parameter controls the falloff rate of the shake effect. Higher values make the shake decay more slowly over time.
- Trauma Falloff (SetTraumaFalloff and GetTraumaFalloff): The traumaFalloff_ parameter determines how quickly the trauma decreases. It specifies how many units of trauma are lost per second.
- Shift Range (SetShiftRange and GetShiftRange): The shiftRange_ defines the maximum displacement range for the camera position. You can set it to control how far the camera moves during the shake.
- Rotation Range (SetRotationRange and GetRotationRange): The rotationRange_ specifies the maximum rotation (pitch, yaw, roll) allowed during the shake. Adjust this to create rotational jitter along with the positional shake.
Finally, the Update method is where the actual shaking logic happens. It modifies the node’s position and rotation based on Perlin noise generated by the perlinNoise_ generator.
Remember to adjust the parameters according to your desired visual effect. The ShakeComponent can add dynamism and excitement to your game!
Learn more about Perlin noise for camera shake at https://www.gdcvault.com/play/1033548/Math-for-Game-Programmers-Juicing