PatHightree / SpaceNavigator

SpaceNavigator driver for Unity3D
MIT License
170 stars 55 forks source link

fix editor delta time #49

Closed ajcampbell1333 closed 1 month ago

ajcampbell1333 commented 2 years ago

I think ViewportController implementation assumes deltaTime in Editor is fixed, therefore doesn't need to be factored into transform updates, yes? Unity logs say it IS fixed, but alas, yet another Unity curveball!

Actual delta time is not fixed in edit mode. Time.deltaTime simply gives non-refreshed junk placeholder data since the var is intended only for use in play mode.

I thought I was going crazy with the velocity of my space mouse. I'm a drummer, so my finger coordination is pretty sensitive to subtle timing shifts. I blamed my own lack of muscle memory for the first hour. After that, no, there was a disturbance in the force.

I logged a DIY deltaTime alongside Unity's Time.deltaTime and found that Time.deltaTime is junk, which explains why my space mouse was consistently hurling my camera into hyperspace whenever my laptop fan turned off. I wasn't such a horrible driver after all!

The fix: ViewportController's translation actions must factor in deltaTime... familiar song-and-dance, except it must be done w/ DIY deltaTime since Time.deltaTime is useless outside play mode. Also, I multiplied in a const of 100f to get us back in the same sensitivity ballpark post-delta. That might be better handled in sensitivity settings in a future push.

I have only applied this fix for Fly mode translation. Haven't had time to fix rotation yet, since the bug is only really noticeable if you try to hold a consistent velocity for a few seconds (which we almost never need for rotation).

Also, I haven't had a chance to try other modes yet, but translation in Fly mode is now buttery smooth. The same fix could be done to all translations and rotations in all modes if you really went to make the whole plugin buttery smooth.

Cheers!

PatHightree commented 2 years ago

Thank you for your looking into this, sounds like a great improvement. Apologies in advance if it takes a while for this to get worked on.

PatHightree commented 1 month ago

Sorry it took 2 years to get to your pull request, but life got in the way. The PR had merge conflicts, so I merged the relevant changes and applied the framerate independent navigation to all modes. I don't know if github will see the PR as accepted because I didn't use the default workflow, sorry about that. But thank you, I'll add your name in the changelog.