- Home /
Change slider value based off of relative mouse movement
Hi. I want to use a UI slider but I want its value to change based on relative mouse movement, not absolute mouse movement. I want it to move without the user having to click and drag the knob. I want the user to be able to click anywhere and have the value change based off of relative mouse movement. So the faster the user clicks and drags the faster the value will change and the slower the user clicks and drags the slower the value will change. I know I can change the slider's value by doing MySlider.value but I am not sure of the correct math to change the value based on how slow/fast the user clicks and drags. Any and all help is appreciated.
Answer by wyatts · May 10, 2019 at 10:48 PM
save the position when clicked to a variable and start measuring the current mouse position from the clicked position. Something like: vector3.distance
If you're looking to accelerate the mouse movement to something different skip the math and check out implementing an animation curve. Then map the mouse movement to your knob along the animation curve.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Trying to move slider based off percentage of screen 1 Answer
Distribute terrain in zones 3 Answers
Change slider value based off of relative mouse movement 0 Answers
How to move slider same amount with different max values when moving it by a percentage Unity 1 Answer