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
0
Question by StarHunter32 · Apr 12, 2013 at 08:13 PM · animationcameramenuloopshake

Camera shake loop in main menu?

Hello,

My question would seem simple and may be discussed before, but so far couldn't find a simple solution. I'd like to make a shaky camera preferably with a script in the main menu.

I guess it's possible to animate, but I think with a script would be more flexible to attach and adjust to any camera?

Here's the result I'm looking for: http://www.youtube.com/watch?v=PPGsGYahjd0

Notice how the camera is hold by human hand and shakes a bit up and down. Thanks a lot in advance!

Comment
Add comment
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

1 Reply

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

Answer by fafase · Apr 12, 2013 at 08:40 PM

Here is something to start with:

 public class MovingCamera : MonoBehaviour {
  Vector3 origin;
  Vector3 target;
  float ratio=0.01f;
  void Start(){
     origin = transform.position;
     InvokeRepeating("ChangeTarget",0.01f,2.0f);
  }
  void Update(){
     transform.position = Vector3.Lerp (transform.position,target,ratio);
  }
  void ChangeTarget(){    
     float x = Random.Range(-1.0f,1.0f);
     float y = Random.Range(-1.0f,1.0f);
     target = new Vector3(origin.x+x,origin.y+y,origin.z);
  }
 }

It takes the original camera position and starts lerping from one position to another. The new position are generated in ChangeTarget every 2 seconds. The new position is constrained in a square of 2X2 with the original point as center.

EDIT: Since it seems to be required in Js:

  var origin: Vector3;
  var target: Vector3;
  var ratio:float=0.01f;
  function Start(){
     origin = transform.position;
     InvokeRepeating("ChangeTarget",0.01f,2.0f);
  }
  function Update(){
     transform.position = Vector3.Lerp (transform.position,target,ratio);
  }
  function ChangeTarget(){    
     var x:float = Random.Range(-1.0f,1.0f);
     var y:float = Random.Range(-1.0f,1.0f);
     target = Vector3(origin.x+x,origin.y+y,origin.z);
  }
 }
Comment
Add comment · Show 6 · 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 StarHunter32 · Apr 12, 2013 at 09:20 PM 0
Share

Thank you! I see it's something clever to start with indeed, but unfortunately I get errors after adding "using UnityEngine; using System.Collections; " at the start.

avatar image fafase · Apr 13, 2013 at 06:56 AM 0
Share

oh you are using Javascript aren't you?

avatar image StarHunter32 · Apr 13, 2013 at 01:20 PM 0
Share

Yes, sir! Thank you. "Using" is the correct word, since I'm beginning to learn. I get two errors on line 12 and 13:

 float x = Random.Range(-1.0f,1.0f);
 float y = Random.Range(-1.0f,1.0f);

UCE0001: ';' expected. Insert a semicolon at the end. Obviously it's not the semicolon.

avatar image fafase · Apr 13, 2013 at 02:44 PM 0
Share

Oops yep, I forgot those ones:

  var x:float = Random.Range(-1.0f,1.0f);
  var y:float = Random.Range(-1.0f,1.0f);
avatar image fafase · Apr 13, 2013 at 04:28 PM 0
Share

One other thing you could try to implement but then I am not sure of the result, would be to have the ratio of the lerp as a sin function with a max amplitude of maybe 0.02. This way you get rid of the slightly sudden move when the target changes. Since sin 0 is 0 and increase in time the movement should look smoother but I have not tried it to tell if it goes nicely.

Show more comments

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to show cursor on specific time? 2 Answers

Loop a script ? 0 Answers

Loop animation issue. 2 Answers

Loop Animation In Script? 2 Answers

Best Practice for Menu System 1 Answer


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