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 DiscGolfer17 · Mar 18, 2013 at 01:43 AM · camerazoomcountdownfovfieldofview

Change field of view over time

I'm trying to smoothly change the camera field of view when my level loads over a 3 second period of time. The camera starts at a 150 field of view and I want it to stop at 55. Along with this I want a countdown to show on the screen like "3", "2", "1" and then the level starts. Does that make sense? I've tried using the Mathf.Lerp() method, but I can't get it to work over a set number of seconds. Also what would be the best way to update the countdown timer along with this? If someone could point me in the right direction, that would be great!

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 Fattie · Mar 18, 2013 at 12:27 PM 0
Share

just use the animator built-in to unity. you can animate any value.

1 Reply

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

Answer by Benproductions1 · Mar 18, 2013 at 03:29 AM

I'll do a bit better than just point you in the right direction :)

if you want a proper countdown, there are really only 2 proper ways of doing it: saving the point you start counting, or saving the point you will stop counting. I prefer the latter!

 //I presume your using Javascript
 
 var timer:float; //the variable that will be when we stop counting
 
 private var countdown:string = "3"; //the countdown on screen
 
 private var tmp:float; //just a temporary float
 
 function Awake() {
     //first we start the timer
     timer = Time.time + 3; //we set it to 3 seconds in the future
 }
 
 function Update() {
     //lets calculate how long till we start
     tmp = timer - Time.time;
     //sets set the countdown string
     if (tmp < 1) {
         countdown = "1";
     }
     else if (tmp < 2) {
         countdown = "2";
     }
     else {
         countdown = "3";
     }
     
     //Now lets properly lerp the Camera fieldofview
     camera.fieldofview = Mathf.Lerp(150, 55, tmp/3); //I don't know if fieldofview is what it's called... I don't have access to the docs right now :)
 }

Hope this helps :) Benproductions1

Comment
Add comment · Show 2 · 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 DiscGolfer17 · Mar 18, 2013 at 12:33 PM 0
Share

Thanks for the code, that was it! I was pretty close, and the only thing I should mention was to divide by a float "3.0f" ins$$anonymous$$d of int "3" in the Lerp() method (I'm using C# and this may not apply to JavaScript). Thanks again!

avatar image Fattie · Mar 18, 2013 at 01:12 PM 0
Share

Here's a common way to do a timer like that ...

http://answers.unity3d.com/questions/419308/subtracting-variable-amount-over-time.html

anther very simple way:

countdown = "3"; yield WaitForSeconds(1); countdown = "1"; yield WaitForSeconds(1); countdown = "1"; yield WaitForSeconds(1); countdown = "0";

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

13 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 avatar image avatar image

Related Questions

Zooming camera using move z position. 0 Answers

Camera movement in a 2D? (like angry birds) 1 Answer

How to accurately zoom (not dolly) and pan Camera to mouse click position 1 Answer

2D is zoomed in/out on different ios devices 0 Answers

Find out if GameObject is in Field of View 2 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