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
1
Question by Cobradabest · Jan 20, 2013 at 01:39 PM · c#buildmousemouselook

Why does my mouselook sensitivity change depending on resolution? (C#)

I have this problem, I decided to build me game to see what it would look like, and I came across a problem, the mouse sensitivity changes depending on resolution, when on the lowest settings, it's too sensitive and on the highest settings it's not sensitive enough.

No errors or warnings display in the editor or on the built game.

How do I fix this?

If it helps, here's my code:

     public enum rotationAxis {MouseX = 1, MouseY = 2}
     public rotationAxis RotXY = rotationAxis.MouseX | rotationAxis.MouseY;
     
     // X Axis
     public float sensitivityX = 400f;
     public float minimumX = -360f;
     public float maximumX = 360f;
     private float rotationX = 0f;
     
     //Y Axis
     public float sensitivityY = 400f;
     public float minimumY = -50f;
     public float maximumY = 50f;
     private float rotationY = 0f;
     
     public Quaternion originalRotation;
     
     // Use this for initialization
     void Start () 
     {
         originalRotation = transform.localRotation;
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (RotXY == rotationAxis.MouseX)
         {
             rotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
             rotationX = ClampAngle(rotationX, minimumX, maximumX);
             Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
             transform.localRotation = originalRotation * xQuaternion;
         }
         if (RotXY == rotationAxis.MouseY)
         {
             rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
             rotationY = ClampAngle(rotationY, minimumY, maximumY);
             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);
             transform.localRotation = originalRotation * yQuaternion;
         }
     }
     public static float ClampAngle (float Angle, float Min, float Max)
     {
         if (Angle < -360)
         {
             Angle += 360;
         }
         if (Angle > 360)
         {
             Angle -= 360;
         }
         return Mathf.Clamp(Angle, Min, Max);
     }
 }
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
1
Best Answer

Answer by asafsitner · Jan 20, 2013 at 01:44 PM

You don't need to multiply mouse input by Time.deltaTime.

Comment
Add comment · Show 3 · 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 Cobradabest · Jan 20, 2013 at 01:59 PM 0
Share

It seems like I do, because when I took it out, it became WAY too sensitivie!

avatar image asafsitner · Jan 20, 2013 at 02:02 PM 1
Share

That's because you multiply the input by 400 on each axis. Try it without multiplication at all.

avatar image Bunny83 · Jan 20, 2013 at 02:10 PM 0
Share

I've converted it into an answer. "$$anonymous$$ouse X" and "$$anonymous$$ouse Y" already return delta values, so don't use Time.delta time in this case.

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

11 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

Related Questions

Distribute terrain in zones 3 Answers

Unity's mouse look causing movement issues 1 Answer

How to disable MouseLook in ingame pause. 1 Answer

Disable JIT compilation in the Editor (Enable Full-AOT mode) 0 Answers

Character Not Rotating 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