   Camera shake
I was going to implement a camera shake. I thought to make it with some sin function like sin(2*x)/x. The shake would start at x = 1 and wound run for some time. But this function goes to infinity. So is there a way to stop it so lets say at x = 5 the function is 0 ?I could force it in code but that wound create a discontinuous function and I would get jerky motion. Also this function at 0 has much higher values. It wound be better if that could be minimized.
shape the falloff function so it goes from 1 to 0 in 5 seconds: f(x) = 1-x/5 Then that would give you: shake(x) = sin(2*x) * (1-x/5) That would be a linear falloff and assuming x starts at 0. This is called easing and here are some nice examples: http://www.gizma.com/easing/;One natural formula to use is sin(2*x)*exp(-x/decay_timescale). It doesn't go to 0 in finite time, but close enough for practical purposes. You could also use a simple controller (e.g., a PID controller, or a damped harmonic oscillator) to make the camera reach the desired position dynamically, and add perturbations to it for shaking. This is a good model of what's actually going on and you can probably get it to look very natural in a wide range of situations.;I've started using perlin noise for camera shakes instead of using spring-like solutions. It gives a similar result visually and will be completely frame-rate independent. Spring/physics style solutions have a habit of behaving differently or even catastrophically falling apart when you run at very low or very fast frame-rates. Of course, that can be fixed by running that bit of the simulation at a fixed frame rate, but that didn't fit in nicely with my camera code which was independent of the fixed-rate update part of my simulation so for me, perlin noise was less hassle. I suppose you lose some control though - e.g. with a physics based solution you could push the camera in a specific direction (say, in response to an explosion or bullet impact) and have it return. With perlin noise, My only control is fading in and fading out the shakiness.;This is another good one I have found on internet.