This content originally appeared on Level Up Coding - Medium and was authored by Christopher Adams
Creating a Simple Camera Shake When the Player Takes Damage in Unity.
Overview:
Today we are going to create a camera shake effect when the player takes damage.
Camera Shake:
We need to create a new script and attach it to the main camera.
- Inside the new script, we need to create some variables. We need a float for the shaking time. a animation curve used for a random vector and a bool to know if our camera is shaking or not.
2. Next, we create a coroutine with a while loop that will shake the camera for the amount of time we set.
3. We also need to create a new method used for starting the coroutine that we will call from the player script.
4. Inside The player Script, we need to create a reference to the camera shake script. Inside the start method, we can use GameObject.Find to find the Main camera and get the Script.
5. Inside the Damage method where we check our current lives, we call the camera shake method.
We should now have a nice and simple camera shake effect.
That’s it for this article.
Thank you for your time and attention.
Creating a simple camera shake when the player takes damage. was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Christopher Adams
Christopher Adams | Sciencx (2022-09-12T03:27:18+00:00) Creating a simple camera shake when the player takes damage.. Retrieved from https://www.scien.cx/2022/09/12/creating-a-simple-camera-shake-when-the-player-takes-damage/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.