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 through 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. The benefit of adding them to a camera manually is that you can control the variables and do specific effects.
(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.)
Camera.Shake(); will make the camera shake!
Camera.Shake(float multi); will multiply the strength when making the camera shake.
Kickbacks have similar implementation.
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); also with an optional multiplier
New in v1.2: Impact Freezes. Like when a game freezes for a split second when you do a strong attack.
Camera.Freeze(); will have it freeze for the amount of time specified on the component.
Camera.Freeze(float time); will freeze for the amount of time specified.
The timescale it will slow down to can be defined on the component.
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
- added impact freezes
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!