Best way to get a true 0-1 position of a draggable UI element?

I’m having an issue with UIDragDetectors where I can never get a true 0-1 relative positional reading of the draggers.

DragUDim2 is always relative to the last previous position, and I can’t just grab the position of the object the grabber is attached to because it for some reason maxes at 1.014 and mins at 0.035 despite the object being in the dead center of the drag bounding box

I essentially just want the dragger to the very left to read 0, and to the very right to read 1

3 Likes

did you try clamping it to 0-1? the values are accumulating, need a clamp :cactus:

I can’t really clamp as it’s just a property of the dragdetector, nor do I really want to insert that into code and clamp it there because that’s going to cause weird issues with offset

Have you considered adjusting the value to get 0 and 1?

this should work:

local Min, Max = 0.035, 1.014 
local curPos = 0 --switch this for whatever u use to get the current position
local AdjustedPos = ( curPos - Min ) / ( Max - Min )

1.014 will return as 1, 0.035 as 0, and whatever is in between will be adjusted accordingly, 0.55 would be 0.526 for example.

First, you need to calculate the range. maxX - minX
Then, calculate the offset of the dragger in relation to the minX. draggerX-minX
Then, normalize to be 0-1. offset / range

local range = maxX-minX
local offset = draggerX-minX
local normalizedOffset = offset/range