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 Cbjfan1 · Apr 16, 2013 at 10:03 PM · mousezoomsensitivitysniper

Sniper Zoom Problem

Hey everyone. I'm working on a script where the mouse sensitivity lowers when I zoom in. Despite what I set the variable to, the sensitivity always instantly goes to 0.004 or something, and I can't move in unless I zoom out. Does anyone know what the problem is? Here is the script:

 var zoomedinx = 4.0;
 var zoomediny = 4.0;
 var zoomedoutx = 10.0;
 var zoomedouty = 10.0;
     
     function Update () {
         if (Input.GetKey ("e")){
         GetComponent("MouseLook").sensitivityX = Mathf.Max(GetComponent("MouseLook").sensitivityX-zoomedinx, 1*Time.deltaTime);
         GetComponent("MouseLook").sensitivityY = Mathf.Max(GetComponent("MouseLook").sensitivityY-zoomediny, 1*Time.deltaTime);
         audio.Play();
         animation.Play();
     }
         if (Input.GetKey ("q")){
             GetComponent("MouseLook").sensitivityX = Mathf.Lerp(GetComponent("MouseLook").sensitivityX, zoomedoutx, 1*Time.deltaTime);
             GetComponent("MouseLook").sensitivityY = Mathf.Lerp(GetComponent("MouseLook").sensitivityY, zoomedouty, 1*Time.deltaTime);
             audio.Play();
         animation.Play();
     }
     }
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 iwaldrop · Apr 16, 2013 at 10:31 PM

I think you meant to do this:

 MouseLook mouseLook;
 
 function Awake()
 {
     mouseLook = GetComponent("MouseLook");
 }
 
 function Update ()
 {
     if (Input.GetKey ("e")
     {
         mouseLook.sensitivityX -= zoomedinx * Time.deltaTime;
         mouseLook.sensitivityY -= zoomediny * Time.deltaTime;
         audio.Play();
         animation.Play();
     }
 
     if (Input.GetKey ("q"))
     {
         mouseLook.sensitivityX += zoomedoutx * Time.deltaTime;
         mouseLook.sensitivityY += zoomedouty * Time.deltaTime;
         audio.Play();
         animation.Play();
     }
 }
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 iwaldrop · Apr 16, 2013 at 10:49 PM 0
Share

You'll probably want to check your current zoom level against a max to decide if you want to zoom in/out any more. In your $$anonymous$$ouseLook script add a value that tracks current Zoom and initialize it to 0.

 int currentZoomLevel;
 int maxZoomLevel;

Then, as you're zoo$$anonymous$$g, subtract or add one to it so you can check against it.

 if (mouseLook.currentZoomLevel < mouseLook.maxZoomLevel && Input.Get$$anonymous$$ey("e"))
 {
     // zoom in
     mouseLook.currentZoomLevel++;
 }

 if (mouseLook.currentZoomLevel > 0 && Input.Get$$anonymous$$ey("q"))
 {
     // zoom out
     mouseLook.currentZoomLevel--;
 }

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

How to set mouse sensitivity through script 1 Answer

sniper mouse sensitivity problem 1 Answer

Scoping script /Camera zoom preferably C# 3 Answers

Mouse look Y axis sensitivity doesn't change 0 Answers

GUI Remove focus from an editor text field when clicking elsewhere. 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