Hey guys, here's a little script I cooked up recently, maybe someone else will find it useful aswell.
It simulates the smooth shake of a portable camera, as seen in some modern action movies. If you want to make it look like your camera is handheld or if something was filmed in a moving car, this is an easy script to do so.
Installation is straightforward - drag it into your unity project and add the PerlinShake script to the Main Camera gameobject. The default values should give you a good subtle shake, but you can modify them to intensify the speed or the magnitude of the shake.
The script contains two functions, StartShake(); and StopShake();, to manually control the shake from code. If you check Play On Awake in the inspector the shake starts right away.
The Top Down checkbox is for when you are using the Topdown mode in Adventure Creator (it flips the Y and Z axis so the camera shakes in the correct directions).
The script is open for improvements, I sort of hacked the duration into it by setting the timer to 9999, if you know a better way feel free to modify it.
Enjoy!
Comments
This seems very useful. Say, I use to edit AC script to increase camera shake to have a value of 100 in slide bar so i can slide to end and really shake the camera. So will this enable be to shake the cam as like the native Camera Shake in AC but with a harsher movement?
If so it will really ease my process altogether.
Having an issue with it, though. It seems to drop the camera to the floor as soon as the scene starts. Any idea why that would happen? It happens when assigned to the 3D demo scene as well.
Thanks for your response. I can tell you that:
1. it is definitely finding the correct camera
2. I've tried it both on game gameras and the main camera with identical results
3. not in TopDown mode
When I substitute the original camera Y instead of computed Y everything works (though obviously the shake is limited to the X axis).
I can find my way around the code pretty easily - but I'm not great at the math. It appears that the Y-calculation is using 0 as the starting point instead of the camera's Y. I'll dig a little more later - but that seems to be practically what's happening.
activeCamera.transform.position = new Vector3(x, originalCamPos.y + y, originalCamPos.z);
I'm trying to work on some code that will allow graceful camera switching when using transitions. Right now if you're using this script and doing any kind of camera animation you will definitely want to stop the shaking effect, animate the camera, then restart the shaking effect to avoid improper camera transforms from getting buffered.