I want to make a camera shake effect when a scary monster comes chasing after you or at least for a cinematic effect then the player can do whatever.
if (isKeyPressed(0x56)) //-- If V key is pressed.
{
static float shakeAmount = cameraYaw;
static float maxShake = cameraYaw + 1.0f * (XM_PI / 4.0);
static float rndJerkiness = ((rand() % 2) - 4);
shakeAmount += cameraYaw + rndJerkiness; // ((rand() % 2) + cameraYaw - 2); // +(XM_PI / 4.0f);
if (shakeAmount > 1.0f * maxShake) {
shakeAmount -= rndJerkiness;
}
if(shakeAmount < -1.0f * maxShake) {
shakeAmount += rndJerkiness;
}
cameraYaw *= shakeAmount;
std::ofstream out("Logs/Camera.log", std::ios_base::app);
out << cameraYaw << ":" << cameraPitch << std::endl;
out.close();
//shakeAmount = 0.0f;
}
As of now it's just tied to the V key for testing purposes. The camera yaw is tied to the updateCamera function which is tied into the pitch, roll and yaw function of the xnamath.h header file.
I'm getting close the camera shakes alright - sometimes it gets out of control and the screen turns black inside the level editor. Possibly something happened and it went past the sky box which is literally impossible because the skybox is scaled for infinity. I'm not sure what's causing that anyways. The random jerkiness is to make it appear jerkier and spazmatic. I was trying to make it random from - 2 to 2. It's outputted for now so I know what's going on inside the log file. The cameraYaw is initialized as 0.0.
I was just wondering if there was something I can do better inside the code?