game development

How To Create A Camera Shake Effect In Unity?

  • imageAgnesh Pipaliya
  • iconJun 29, 2022
  • icon196
  • icon
  • icon
image

Are you trying to give some real effect to your game? 

Camera shake is one of them. It gives the feeling of chaos, disorientation, or realism. And it is usually used in action games while moving at a fast speed or when a large impact or explosion occurs.

You can use this camera shake effect for your game project to create an effective game with a compelling story. Take a look. 

 

 

Step - 1: Create Project

First of all create a brand new unity 3D project and set the scene as shown below. create some other game objects like sphere, cube, etc.

 

 

Step - 2: Import DoTween Plugin

Now import DoTween plugin in to your project from unity asset store which are totally free.

 

 

Step - 3: Create Camera Shaking Script

Now create new C# script and give name what you like, in my case I am just save this with names like “MyCameraShaking.cs”.

Next just copy and paste the below mentioned code into your script, I set this code in to my “MyCameraShaking.cs” and then save the script.

Now create new game object name with “Shake Manager” in hierarchy and assign this script to this game object and give camera reference to the script from hierarchy.

 

 

Step - 4: Test Demo

Now jump run the scene and you will see your all environment in the scene is shaking with some vibration frequency that you set in the code.

Explanation Of DoTween Shake Method

DOShakePosition(Float Duration, Float/Vector3 Strength, Int Vibrato, Float Randomness, Bool Snapping, Bool FadeOut)

Shakes a Transform's localPosition with the given values.

duration - The duration of the tween.

strength - The shake strength. Using a Vector3 instead of a float lets you choose the strength for each axis.

vibrato - Indicates how much will the shake vibrate.

randomness - Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). Setting it to 0 will shake along a single direction.

snapping - If TRUE the tween will smoothly snap all values to integers.

fadeOut (default: true) - If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not.

Conclusion

In this blog, you have learned about the camera shake effects. You can use it in different ways for your game projects, whether it is to portray a scene where a bomb goes off, a barrel explodes, or you get hit by a gun; it is effective everywhere. 

Develop your games with a camera shake effect to give a real view to your users. 

 

Table of Content

Steps

Your Future,

Our Focus

  • user
  • user
  • user
  • user

Start Your Digital Transformation Journey Now and Revolutionize Your Business.

0+
Years of Shaping Success
0+
Projects Successfully Delivered
0x
Growth Rate, Consistently Achieved
0+
Top-tier Professionals