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 calbar · Nov 06, 2013 at 09:08 PM · inputframeratejittergetaxis

How can I prevent Input.GetAxis from sporadically reporting deltas of 0.0?

I'm using the mouse to drag an object around. On every single frame, I use that object's change in position to drive certain effects (like rotation, color, etc.)

Unfortunately, these effects were very jittery, even under smooth, constant mouse movement. So I decided to log Time.frameCount, Input.mousePosition, and Input.GetAxis deltas inside an Update method. Here's what that looks like while making smooth circles with the mouse:

 Frame: 31 Position: (477.3, 230.8, 0.0) Delta: (1.8, -1.3)
 Frame: 32 Position: (477.3, 230.8, 0.0) Delta: (0.8, -0.4)
 Frame: 33 Position: (522.5, 217.5, 0.0) Delta: (3.5, -0.6)
 Frame: 34 Position: (522.5, 217.5, 0.0) Delta: (0.0, 0.0) <--
 Frame: 35 Position: (565.5, 220.4, 0.0) Delta: (3.7, 0.9)
 Frame: 36 Position: (565.5, 220.4, 0.0) Delta: (0.0, 0.0) <--
 Frame: 37 Position: (586.3, 239.0, 0.0) Delta: (1.3, 2.2)
 Frame: 38 Position: (589.3, 260.5, 0.0) Delta: (0.2, 1.4)
 Frame: 39 Position: (589.3, 272.4, 0.0) Delta: (-0.2, 2.4)

For some reason Input regularly fails to update the mouse on some frames, as seen on frames 34 and 36 above.

Things I've tried:

  • Swapping out my mouse and using the MacBook trackpad to rule out hardware polling issues. (same results)

  • Caching deltas and reusing the previous when 0.0 is detected, correcting for missed frames after. (feels kinda "swimmy")

  • Calculating my own deltas using mousePosition (same results, naturally)

  • Lerping the mouse-driven object's position. (degrades response time)

It's been suggested that Input is only updated 20 times per second (or less) under constant mouse movement. I'm testing at 60 fps, so that would explain the behavior I'm seeing.

But I'm at wit's end as to how to fix or compensate for this. For example, how could you possibly create a smooth first person shooter when view angle is directly driven by mouse movement but the mouse is considered momentarily stationary at least 1 out of every 20 rendered frames?

Thanks for any insights!

Comment
Add comment · Show 9
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 Starwalker · Nov 06, 2013 at 09:44 PM 0
Share

The polling of Input is done on Update() or FixedUpdate()? If its Update(), did you try it in FixedUpdate()?

FixedUpdate Info, how to

avatar image calbar · Nov 07, 2013 at 03:50 AM 0
Share

From my research, I understand that Input is done at the beginning of Update(), and that you should avoid polling Input in FixedUpdate() because it is not synchronized with the framerate and therefore you could miss your chance to respond to updates or events.

I could always be corrected, though, because it's all new to me!

avatar image Josh707 · Nov 07, 2013 at 03:57 AM 0
Share

Yes, input should not be in FixedUpdate() at least for buttons, I'm not sure about axes. I tried having a Coroutine wait for fixed update and it constantly missed my button presses.

avatar image calbar · Nov 07, 2013 at 04:03 AM 0
Share

I actually just tested this debug in FixedUpdate(), and yeah, it has the same issues.

Fwiw, I have my Fixed Timestep set to 0.04 for performance reasons - 25 fixed frames per second - which is close to the 20 fps that Input is supposedly running at, so I guess it's not surprising they exhibit similar behavior.

avatar image Huacanacha · Nov 07, 2013 at 04:14 AM 0
Share

You could try adding some smoothing yourself by applying the average of the last 2 or 3 deltas. Quick and dirty but it may help ;)

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

Achieve framerate independent AddTorque rotaion with mouse drag. 2 Answers

Why does holding down any button cause ~20-30 FPS loss? 1 Answer

[SOLVED] Input.GetAxis("Horizontal") returns wrong value? -1 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Get axis literal keyboard or mouse value... not possible? 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