Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 farret3 · May 09, 2013 at 03:05 AM · c#camerazoomfieldofview

Script to constantly change FOV?

I've only been using Unity for a few days (for class) and I'm trying to create a scene to simulate being drunk. One of the things I'm trying to implement to do this is a script on the main camera that will smoothly slide the Field of View back and forth between 60 and 120 degrees. I'm having little success so far, as my current script only ticks back and forth between 58 degrees and 60 degrees. Can anyone set me on the right path?

My script:

 using UnityEngine;
 using System.Collections;
 
 public class FOValter : MonoBehaviour 
 {
     
     public float currentFOV = 90f;
     public float rateOfChange = 0.1f;
     public float ticker = 0;
     
     void Update()
     {
         if (ticker == 30)
         {
             if (currentFOV > 118 || currentFOV < 62)
             {
                 rateOfChange *= -1;
             }
             currentFOV += rateOfChange;
             Camera.main.fieldOfView = currentFOV;
             ticker = 0;
         }
         ticker++;
     }
 }
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 robertbu · May 09, 2013 at 04:03 AM

Here is an approach.

 public class FOValter : MonoBehaviour {
  
     public float startFOV = 90f;
     public float deltaFOV = 28f;
     public float speed = 10f;
     private float timer = 0f;
  
     void Update()
     {
         //if (ticker == 30)
         {
         Camera.main.fieldOfView = startFOV + Mathf.Sin(timer * speed) * deltaFOV;
         timer += Time.deltaTime;
            }
     }
 }

'deltaFOV' is how far on either side of the startFOV it will reach.

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 farret3 · May 09, 2013 at 04:17 AM 0
Share

Worked like a charm, thank you very much!

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

Camera Zoom/custom projection having trouble. 1 Answer

Change field of view over time 1 Answer

Keep Player + Party and/or Targeted Enemies in Camera Focus 1 Answer

Avoid/Minimize Sprites extrapolation in 2D while camera changes size 0 Answers

Camera movement in a 2D? (like angry birds) 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