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 Ahmad_Talal · Jan 23, 2014 at 06:27 PM · camerazoom

Increase camera Zoom

Hello guys, I have this script which zoom the camera to a field of view of 1, But its not enough for my scene. My scene is huge. How Do I make the camera to zoom to a longer distance.

My script is below,

     var zoom : int = 20;
     var normal : int = 60;
     var smooth : float = 5;
     private var isZoomed = false;
     function Update () {
     //if(Input.GetKey("z")){
     if(Input.GetAxis("Mouse ScrollWheel")){
     isZoomed = !isZoomed;
     }
      
     if(isZoomed == true){
     camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
     }
     else{
     camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
     }
     }
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

Answer by giudark · Jan 23, 2014 at 06:50 PM

Here you can find many "famous" camera script : Scripts/Controllers In particular i suggest you to adopt MouseOrbitZoom without the orbit part if you don't want it:

 public Transform target;
 public float distance = 10f;
 public float maxDistance = 100;
 public float minDistance = 5f;
 public int zoomRate = 40;
 public float zoomDampening = 5.0f;
 private float currentDistance;
 private float desiredDistance;
 private Vector3 position;

 public void Start(){
      if (!target){
         var go = new GameObject("Cam Target");
         go.transform.position = transform.position + (transform.forward * distance);
         target = go.transform;
     }

     currentDistance = distance;
     desiredDistance = distance;
     position = transform.position;
 }

 public void LateUpdate(){
     // scrollwheel affect the desired ZOOM distance
     desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
     //clamp the zoom min/max
     desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
     // For smoothing of the zoom, optional
     currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);

     // calculate position based on the new currentDistance
     position = target.position - (Vector3.forward * currentDistance);
     transform.position = position;
 }

in the ispector you can modify the zoom rate, min and in particular max :)

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 Ahmad_Talal · Jan 23, 2014 at 07:04 PM 0
Share

thank u very very much

avatar image Ahmad_Talal · Jan 23, 2014 at 07:07 PM 0
Share

well unity answer area is awesome

avatar image Ahmad_Talal · Jan 23, 2014 at 07:17 PM 0
Share

what type of this script is this, its not java script nor c#

avatar image giudark · Jan 23, 2014 at 07:39 PM 0
Share

yes sure, my fault, this is C# now :)

avatar image Ahmad_Talal · Jan 24, 2014 at 09:53 AM 0
Share

Well your script is good but not enough. What I want is to zoom the camera but my camera remains still. When I apply your script, what it will do, it will zoom the camera but also move the camera from its position. I dont want that. I just want to zoom but not to move my camera from my still position. thnx

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

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

Related Questions

Camera zooming in and out 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problems with second Camera zoom and display 1 Answer

I am writing a camera script, but it seems not to be working. Any suggestions? 1 Answer

How to zoom camera in x amount of seconds 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