I have the above code to move my GameObject vertically (along the y-axis). This works fine except that I want the object to move relative to my motion i.e.
If I tilt the phone some X amount very fast it will move distance Z whereas if I tilt the phone with amount X but slower the distance will be A where Z > A.
I’ve tried to get the current reading subtracting it from the previous reading and multiplying it with the rest but apart from causing a jittery effect it didn’t work exactly as I wanted it to.
Can some one help me achieve this ? I’m quite new to Unity.
from what i understand you basically want it so if you move really fast you impart some additional momentum to the object so it moves further.
your got a jittery affect because you multiplied by too high a number (basically you moved the mouse so great a distance in so short a time it skipped whole sections of the screen before being rendered again)
you could prevent this by doing addition instead such as
if current - previous <= 1
add 0
if current - previous <= 5
add 1
if…
all the way up to whatever is a max which doesnt cause jittering
like
else
add 10
alternatly if you used an algorithm you could simply make sure the number returned by that wasn’t too high if it was set a limit and redefine it to the max limit so for example
if your old algorithm was
new_x = (current - previous) * old_x
now you would add
if new_x > MAX_FOR_SMOOTH_TRANSITION
new_x = MAX_FOR_SMOOTH_TRANSITION
finally if you really want to get complicated
read this paper on how microsoft made an algorithm for the mouse acceleration in windows.
(which is basically what your doing)
google windows mouse acceleration algorithm for greater detail
Good to know that my reasoning was correct after all. :) Good idea, thanks for the tips. I'll try it out and see how it goes.
Good to know that my reasoning was correct after all. :) Good idea, thanks for the tips. I'll try it out and see how it goes.
– anon90445360Great my old algorithms is now working perfectly :) !!
– anon90445360