Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by dmpaskiet · Sep 01, 2010 at 03:55 AM · camerashake

Is it possible to shake the camera?

So here is what I've got and what I'm trying to do. I have a pretty basic 2D platform game I'm trying to set up. At one point when the player touches a trigger it causes some debris to fall down and take out a platform ahead of the character. I have that running fine, but what I would like to do is cause the camera to shake for a second or two to simulate a small earthquake before the debris comes down.

I looked around and didn't see any scripts to do it already out there, and no similar questions on here. So is it possible? And if so any help on getting it working would be greatly appreciated.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image insominx · May 17, 2013 at 08:20 PM 0
Share

This blog covers it pretty well: http://unitytipsandtricks.blogspot.com/2013/05/camera-shake.html

4 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Eric5h5 · Sep 01, 2010 at 04:18 AM

Of course it's possible, you just program it to do that. This has a script with a camera shake function in it; it might work for an earthquake, but if not, then make another function that works the way you want.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image agentsmith · Oct 07, 2010 at 09:37 PM 0
Share

Worked really well!!

avatar image .hooligan · Jan 26, 2011 at 12:30 PM 0
Share

Hey Eric I checked out that camera shake from that game example. I'm having trouble converting it to c though. The thing that has me stumped is the yeild. Am I supposed to make cameraShake return IEnumerator and replace the yeild with yield return new WaitForSeconds(0); ? And is this method just supposed to be called once or is it supposed to be inside update?

avatar image .hooligan · Jan 26, 2011 at 12:35 PM 0
Share

Also how do you cast a int to a bool in c heres the line that I'm having trouble with.

int shake = numberOfShakes; while (shake) {

avatar image Eric5h5 · Jan 26, 2011 at 06:53 PM 0
Share

Just call it once. yield = yield return null.

avatar image Un4given · Jun 02, 2011 at 02:34 PM 0
Share

I cant seem to get this to work, is there a trick to it?

avatar image
1

Answer by Thom Denick · Mar 21, 2011 at 09:32 PM

You can easily implement this by using Unity's Animation system.

1.) Add an Animation Component to your camera if it doesn't already have one.

2.) Create a new animation for the camera.

3.) Add curves for Position.x, Position.y, Position.z

4.) Now create a few Keyframes along the first 50 or so frames.

5.) Go to each of your Keyframes and move each position curve slightly up and down, and play until you get it close to what you want. Save the animation.

All you have to do to call the animation via script (assuming it's assigned as the default anim on the camera) is:

myCamera.animation.Play();
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-3

Answer by Bora Kasap · Mar 06, 2011 at 08:26 AM

i'm using PC, could someone paste the codes here? :/ i made a vertical shaking effect like that, but i need a smoother one :/

////////////

var to_up : int = 0; var timer_up : int = 85; var timer_down : int =85;

function Update () { if (to_up == 1) { transform.Translate(Vector3.up Time.deltaTime/6); timer_up -= 1; } else if (to_up == 0) { transform.Translate(Vector3.up -Time.deltaTime/6); timer_down -= 1; }

if (timer_up == 0) { to_up = 0; timer_up = 85;}

if (timer_down == 0) { to_up = 1; timer_down = 85;}

}

///////////////

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by paulidis · Jul 14, 2011 at 05:41 PM

use itween by pixelplacement

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Demigiant · Nov 05, 2011 at 11:00 AM 0
Share

iTween shake methods are terribly buggy: objects completely lose parent transforms while you use them.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Camera Shake on pressing Fire1 (used to fire bullets).. 0 Answers

iTween.ShakePosition freezes Rotation 0 Answers

2.5d camera control script 1 Answer

Camera Toggle script 1 Answer

Loop a script ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges