Screenshake Asset for Unity
A downloadable tool
Unity asset made for Toolbox Jam!
Wanted to make a little asset for doing screenshake and kickback, since every project can use it, I guess. It works with other camera movement scripts and shouldn't interfere with a moving camera.
After being imported into Unity, the "Screenshake" or "Kickback" components can be added thru the component menu. (Component > Utility)
On cameras, you can call Camera.Shake();
Or Camera.Kick(Vector3 direction);
You can also call these on cameras that don't have the components attached, and they will be added at runtime.
(You can add these to normal objects too, just don't mind that the asset is called "Screenshake". You'll have to call Screenshake.Shake() or Kickback.Kick(Vector3 dir) which sounds kinda weird, but it works.)
In the inspector, double-click on the "ScreenshakeData" field to edit the properties! You can adjust how long it lasts, adjust the direction, and adjust intensity curve! You can even save multiple presets!
Camera.Shake(); will call whatever you have saved to "default".
Camera.Shake(float multi); will multiply the strength of the default setting.
Camera.Shake(string name); will let you call a different saved preset by name. Camera.Shake(string name, float multi); will call a saved preset with a multiplier.
Kickbacks have similar implementation
and can also be edited with "ScreenshakeData".
Camera.Kick(Vector3 direction); will have the camera get kicked back in that direction! The direction will be a normalized value.
Camera.Kick(Vector3 direction, float multi); to multiply it
Camera.Kick(string name, Vector3 direction); to call a saved preset and Camera.Kick(string name, Vector3 direction, float multi); to multiply a preset!
Got any more ideas for this? Lemme know! I'm trying to figure out if this is the best implementation for a quick screenshake asset. Also could use a better, more generalized name! And better example pics. And real docs, oops
- no longer uses screenshot data file.
- curves initialize more usefully.
- relative rotation to camera toggle.
- way to control screenshake axises
Click download now to get access to the following files:
Log in with your itch.io account to leave a comment.
looks great but I'm experiencing an issue. I attached a Screenshake script to my Main Camera, and when there is an explosion ingame I call my gamecontroller, which invokes Camera.current.Shake();
On 2/3 of the explosions it works, but sometimes it doesn't and I get the following error:
NullReferenceException: Object reference not set to an instance of an object
ScreenshakeCameraExtentions.Shake (UnityEngine.Camera cam) (at Assets/Clavian/Screenshake/ScreenshakeCameraExtentions.cs:9)
GameController.Explosion () (at Assets/Scripts/GameController.cs:51)
DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:34)
Line 9 of ScreenshakeCameraExtentions does this:
Screenshake shake = cam.transform.GetComponent<Screenshake>();
Any idea why it's failing to get the Screenshake component?
Looked into it, and the problem seems to be that Camera.current is meant for low-level render control, only: https://docs.unity3d.com/ScriptReference/Camera-cu...
Instead of using Camera.current, try using Camera.main or a public Camera variable!