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 OwlInTheCupboard · Jul 04, 2020 at 04:11 PM · inputmouseaxis

Mouse input erratic

Hello,

I am trying to follow a tutorial to make a FPS controller. The first section is making the player turn left and right. The issue is that when I use the following code the camera turns erratically. It appears to be that the values are occationally massive rather than the correct delta.

 void FixedUpdate()
     {
         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
         float forward = Input.GetAxis("Vertical") * speed * Time.deltaTime;
 
         playerOBJ.transform.Rotate(Vector3.up * mouseX);
 
         playerOBJ.transform.Translate(Vector3.forward * forward);
 
         Debug.Log(forward * Time.deltaTime);
     }

The code also tests the vertical axis and that has no problems so this isn't a frame rate issue just wierd value issue.

I have multiple monitors and using version 2019.4.2f1

Thanks!

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 Eno-Khaon · Jul 04, 2020 at 06:09 PM

Actually, this IS a framerate issue.

By multiplying a per-frame value by Time.deltaTime, you're causing it to become framerate-dependent. You'll want to crank your mouseSensitivity waaaay down (~1/60 for example, assuming your framerate has been capped).

 float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;// * Time.deltaTime;
 float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;// * Time.deltaTime;

Because the Mouse Axis inputs are already absolute changes to mouse position, they don't need to be given variable scaling.

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 OwlInTheCupboard · Jul 04, 2020 at 06:22 PM 0
Share

I have tried both, with and without, its not high sensitivity but random values.

Enabling vsync fixes the issues. I think its a combination of windows multi screen stutter and high frame rate. In my test scene I am hitting 2000+ frames/s at least that is what stats is reporting. When I enable vsync I do not have the issue anymore.

Further to this I have the windows multiscreen stutter. enabling vsync and unplugging my other monitors does not produce this error anymore. What is odd however is how its getting its values, your talking every odd frame your getting an input value 10 or 100 times the size of normal values from the mouse input.

avatar image Eno-Khaon OwlInTheCupboard · Jul 04, 2020 at 09:22 PM 0
Share

Ah, there's something I overlooked. If your framerate is that high, you're probably also losing a huge amount of input to reading mouse input from the wrong function. You want your input to be read from Update() ins$$anonymous$$d of FixedUpdate(), since that's where it's actually processed in the first place. With a framerate of 2000 fps, you're probably dropping 39 out of every 40 mouse inputs!

Furthermore, spikes in movement would then likely be caused every time something hits your framerate briefly. For example, if your framerate is 2000, then it drops to 100 (for one or two frames, for example), then your mouse input would suddenly spike from 1/40 frames registering input to 1/2, or a ~20x spike in movement registered for that frame.

Input is processed during, and should be read from Update(). Physics engine processing (like, Rigidbody.AddForce()) take place during FixedUpdate().

avatar image OwlInTheCupboard Eno-Khaon · Jul 04, 2020 at 09:27 PM 0
Share

Thanks,

I have fixed it but also moved to the new input system so the implementation is slightly different now.

I think you are right but obviously haven't tested it. I also think the issue is with a know bug with windows 10 which causes stuttering on windows when using multiple screens (something they are apparently fixing come patch 2004!)

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

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

Related Questions

Rotating 2D Sprite on 1 Axis Using 2 Input Axes 0 Answers

Cursor/Mouse movement to controller 0 Answers

Multiple Constant Force Inputs at once? 1 Answer

Input Axis Mouse ScrollWheel 1 Answer

OnMouse menu 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