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 xXTURDLEXx · Nov 28, 2012 at 06:38 AM · javascriptfpsspeedzoomsensitivity

How to change the sensitivity on right click (when zoomed in)

I have acript to zoom in the camra but i want it to zoom in faster and change the sensitivity when zoomed in because it is to fast( because the cam has smaller field of view) if you can fix please tell me how!

Script:

private var baseFOV : float;

 function Start () {
     baseFOV = Camera.main.fieldOfView;
 }

 function Update () {
          if (Input.GetMouseButton(1))
       Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,35,Time.deltaTime);
          else 
             Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,baseFOV,Time.deltaTime);
 }
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

2 Replies

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

Answer by DeveshPandey · Nov 28, 2012 at 07:12 AM

I remember that this was my answer. :)
Anyway try this, change the speed variable and enjoy :)

 private var baseFOV : float;
 private var speed : float = 25f;
 
 function Start () {
     baseFOV = Camera.main.fieldOfView;
 }
 
 function Update () {
          if (Input.GetMouseButton(1))
               Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,35,Time.deltaTime*speed);
          else 
             Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,baseFOV,Time.deltaTime*speed);
 }
Comment
Add comment · Show 7 · 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 xXTURDLEXx · Nov 28, 2012 at 08:24 AM 0
Share

Yeah sorry, forgot to give credit :)

avatar image DeveshPandey · Nov 28, 2012 at 08:26 AM 0
Share

O$$anonymous$$, no problem. if this works then mark as accepted and thumb up, Thanks!

avatar image xXTURDLEXx · Nov 28, 2012 at 08:43 AM 0
Share

One more question, how do u change the senitivity wile zoomed in?

avatar image DeveshPandey · Nov 28, 2012 at 09:16 AM 0
Share

not getting you, tell me clearly what you want to do? Sorry for my bad English. :)

avatar image xXTURDLEXx · Nov 28, 2012 at 09:40 AM 0
Share

When I right click it zooms in right but when I do that it changes the cameras field of view. doing this makes it seem like the sensitivity is high, is there a way to lower this while zoomed in (Right Click)?

Show more comments
avatar image
0

Answer by Flynn · Nov 28, 2012 at 07:04 AM

Using AOV instead of FOV might help!

 public var minFOV : float = 1;
 public var baseFOV : float = 0;
 public var czoom : float = 0;
 
 function Start ()
 {
     baseFOV = Camera.main.fieldOfView;
 }
 
 function Update ()
 {
     //Step one: Calculate the percentage of the maximum zoom that should be used (this is actually the perscentage of the maximum AOV (area of view)    
         if (Input.GetMouseButton(1))
             czoom = Mathf.Lerp(czoom, 0.0, Time.deltaTime);
         else 
             czoom = Mathf.Lerp(czoom, 1.0, Time.deltaTime);
 
 
 
     //Step two: Calculate the wanted Aov from our zoom percentage
         var maxAov : float = FOVtoAOV(baseFOV, Camera.main);
         var minAov : float = FOVtoAOV(minFOV, Camera.main);
         var aov : float = Mathf.Lerp(minAov, maxAov, czoom);
      
      
        //Step three: Calculate the corresponding FOV for our wanted AOV
            var fov : float = AOVtoFOV(aov, Camera.main);
    
    
        //Step four: Apply the fov!
        Camera.main.fieldOfView = fov;
 }
 
 
 function FOVtoAOV(fov : float, cam : Camera)
 {
     return (fov/90.0) * cam.farClipPlane;
     //At 90 degrees the width of the AOV will be directly proportional to the distance of the camera
 }
 
 function AOVtoFOV(aov : float, cam : Camera)
 {
     return (aov/cam.farClipPlane)*90.0;
     //When our AOV equals the farClipPlane, the FOV will be 90 degrees
 }


Let me know how this works! :) You may have to fine tune the speeds as it does zoom out rather quickly -- but zoom speed slows down as you get to smaller zoom : D

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 xXTURDLEXx · Nov 28, 2012 at 08:42 AM 0
Share

It zooms rather slowly and FOREVER but other wise it's great!

avatar image Flynn · Nov 28, 2012 at 11:37 PM 0
Share

Change czoom = $$anonymous$$athf.Lerp(czoom, 0.0, Time.deltaTime); to czoom = $$anonymous$$athf.Lerp(czoom, 0.0, Time.deltaTime * yourspeed); to adjust the zoom in and zoom out speeds :)

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

12 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

Related Questions

gun scope cam not working 3 Answers

Modern Warfare Styled Zoom? (Javascript issue) 0 Answers

Shooting system not working 1 Answer

FPS sniper zoom effect without black texture? 3 Answers

Restricting camera movement in first person camera? 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