Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[DEPRECATED] EZ Camera Shake v1.0.0

Discussion in 'Assets and Asset Store' started by Cramonky, Apr 10, 2015.

  1. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    Hello all,

    I am proud to announce the release of my camera shaking system, EZ Camera Shake.


    EZ Camera Shake is a versatile camera shaking system that can be used in a large variety of situations. From explosions to earthquakes, from rough roads to bad trips, this system has you covered!

    *Works in Unity 4.5+ and Unity 5!

    Features:
    • One-Shot and Sustained shakes.
    • Magnitude and Roughness properties, as well as modifiable Position and Rotation influence to allow for a great variety of effects.
    • Ability to store and modify all shake properties at runtime.
    • Includes several shake presets.


    Feedback is greatly appreciated! And of course if you find any bugs or issues post them here and I will submit fixes for them promptly!

    *Please be aware that use of this package may require slight modification of existing camera movement scripts. See the Guide & Documentation for details.
     
    Last edited: Feb 28, 2016
    eobet and jreisam like this.
  2. jreisam

    jreisam

    Joined:
    Jul 17, 2015
    Posts:
    1
    Thank you !! well done
     
  3. eshan-mathur

    eshan-mathur

    Joined:
    Nov 22, 2011
    Posts:
    118
    Reloading a scene with a EZCameraShake in it breaks the script - the instance dictionary is static and thus when the scene is reloaded, it attempts to add a new instance under the same key (gameObject.name) and throws an error.
     
  4. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    I feel pretty silly for overlooking something so obvious...

    Luckily it seems to be a simple fix, and I will submit an official update right away. In the meantime, you can add this code to the CameraShaker.cs script to fix the problem:
    Code (csharp):
    1. void OnDestroy()
    2. {
    3.     instanceList.Remove(gameObject.name);
    4. }
     
  5. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    Hey wilbertng,

    Sorry for the delay. I've updated the package to include some sample scripts that hopefully will be useful.
     
    RendCycle likes this.
  6. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    Hello. I am creating a constant shake effect. How do I change the values once the shake is going?

    Also how do I stop the shake?
     
  7. Cramonky

    Cramonky

    Joined:
    Apr 1, 2013
    Posts:
    186
    Hey roger0,

    The first thing you would need to do is save a CameraShakeInstance object in your script, like this:

    Code (csharp):
    1. private CameraShakeInstance myShake;
    2.  
    3. void Start()
    4. {
    5.     myShake = CameraShaker.Instance.StartShake(<parameters go here>);
    6.  
    7.     //If don't want your shake to be active immediately, have these lines:
    8.     myShake.StartFadeOut(0);
    9.     myShake.DeleteOnInactive = false
    10. }
    Then you can access myShake's properties like ScaleMagnitude, ScaleRoughness, etc. To stop the shake you can call myShake.StartFadeOut(<fade out time, in seconds>). If you don't want your shake to be deleted once it is no longer active (i.e. the fade out has finished and the magnitude is 0) you need to set myShake.DeleteOnInactive = false.

    Here's a sample script (provided in the latest update of the package) which demonstrates altering a shake's properties dynamically:
    Code (csharp):
    1.  
    2. /*
    3.  * This script shakes the camera based on the player object's distance to the object this script is attached to.
    4.  */
    5. public class ShakeByDistance : MonoBehaviour
    6. {
    7.     //Our player object.
    8.     public GameObject Player;
    9.  
    10.     //The maximum distance. If the player is farther away than this distance then no shaking will be visible.
    11.     public float Distance = 10f;
    12.  
    13.     //Our saved shake instance.
    14.     private CameraShakeInstance _shakeInstance;
    15.  
    16.     void Start()
    17.     {
    18.         //Create the shake instance. We will modify its properties in Update()
    19.         _shakeInstance = CameraShaker.Instance.StartShake(2, 14, 0);
    20.     }
    21.  
    22.     void Update ()
    23.     {
    24.         //Get the distance from the player to this object.
    25.         float currentDistance = Vector3.Distance(Player.transform.position, this.transform.position);
    26.  
    27.         //Scale the magnitude of our saved shake, so that the scale is higher the closer we get to the object.
    28.         _shakeInstance.ScaleMagnitude = 1 - Mathf.Clamp01(currentDistance / Distance);
    29.     }
    30. }
    31.  
     
  8. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Hi. Actual version requires Unity 5. Could you please send me link with a version that works with unity 4.7?
     
  9. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    Hello again. I have multiple cameras in my scene and I want to apply the camera shake effect onto all of them at once, but it seems like it only works for one. When I call CameraShaker.Instance.ShakeOnce it only affects one camera in the scene.

    Also when I parent the camera with the camera shaker script on it to another object, it automatically make its position exactly the same as the parent. Its not a serious problem but any way to fix it?

    Thanks
     
  10. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Nice asset thank you. Only one thing I can comment on, the manual's "how to" section is incomplete.

    For anyone else trying to use this do the basic setup as instructed in the doc:
    1. create an empty object and put the camera into it
    2. make sure the camera's transform is all zeros
    3. If you need your camera to be at specific coordinates and rotations set them up on the container object created at step 1

    CameraShaker.cs uses its own namespace. In otherwords it works as if it was a built in command, you dont have to do anything but load the script on the camera. All you have to do is:
    1. Open your script in mono whatever editor you use
    2. Start typing EZCameraShake and you will see the built in commands show up
    3. Refer to the manual to know what each options do
    Note.: The first level commands dont have a description but once you get down further it does show basic info on what each command does.

    Here is an example that starts the "Explosion" preset:

    EZCameraShake.CameraShaker.Instance.Shake(EZCameraShake.CameraShakePresets.Explosion);

    NOTE.: To make this work with a UI, you need to set the Cavas render mode to world space in the inspector.
     
    Last edited: Oct 27, 2016
  11. NAiLz

    NAiLz

    Joined:
    Apr 17, 2013
    Posts:
    88
    @tzc8 Thanks a ton for this setup tip. It was driving me crazy, trying to figure out why my camera kept moving with this script attached.
     
  12. LeonmFF

    LeonmFF

    Joined:
    Sep 11, 2014
    Posts:
    8
    Hello \o/

    First, thank you so much, you did a great job and helped out many of us, a lot!

    And now, trying to help anyone that may encouter the same problems I did ("it attempts to add a new instance under the same key (gameObject.name) and throws an error.").

    Here's what I've changed:
    In the CameraShaker I've removed the OnDestroy and the Awake and replaced with:

    Code (CSharp):
    1.        private void OnEnable()
    2.         {
    3.             SceneManager.sceneLoaded += RemoveInstance;  
    4.         }
    5.  
    6.         private void OnDisable()
    7.         {
    8.             SceneManager.sceneLoaded -= RemoveInstance;
    9.         }
    10.  
    11.         private void RemoveInstance(Scene scene, LoadSceneMode sceneMode)
    12.         {
    13.             instanceList.Remove(gameObject.name);
    14.  
    15.             Instance = this;
    16.  
    17.             instanceList.Add(gameObject.name, this);
    18.         }
    Remember to add "using UnityEngine.SceneManagement;". Unity 2018 here, \o/
     
  13. romain1994

    romain1994

    Joined:
    Oct 23, 2018
    Posts:
    26
    hello,
    first of all I would like to tell you that your camera shake is amazing, the best I have seen so far.
    but I am have a little problem with it on multiplayer online. the script is attached to my player prefab's camera, and when a new player joins the game it crashes due to "add a new instance under the same key (gameObject.name)". Do you know how I can fix that?
    I use networkManager.matchMaker.JoinMatch if it helps.

    Thanks in advance.
     
  14. romain1994

    romain1994

    Joined:
    Oct 23, 2018
    Posts:
    26
    or if anyone could help that would be great
     
  15. Wachalala

    Wachalala

    Joined:
    Nov 19, 2018
    Posts:
    12
    Hello,

    This asset look really great.
    I was wondering if it's possible to shake UI of a 2D game ?
    I can't manage to do this.

    Thank you :)
     
    Last edited: Jan 7, 2019
  16. ashgamestudio

    ashgamestudio

    Joined:
    Apr 14, 2018
    Posts:
    1
    asset store says this plugin is deprecated
     
  17. StrawberryJellyfish

    StrawberryJellyfish

    Joined:
    Oct 29, 2016
    Posts:
    23
    hippocoder likes this.
  18. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Nice gesture, hope it will lead to more sharing and learning.
     
  19. Will_Dev

    Will_Dev

    Joined:
    May 24, 2017
    Posts:
    27
  20. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Usual reason will be time, 9 times out of 10.