Hi all,
I’ve just migrated to Unity’s new input system and quickly realized that the new touch system no longer has a property for Touch.radiusVariance. I use this property to normalize input sizes for a range of iOS devices and without it I will be forced to rewrite a perfectly functional input class. It would be much simpler if I could recreate the radiusVariance property that Unity used in their old input system. Does anyone know how Unity calculated radiusVariance in the past?
After firing up a build that uses the old input system I was able to gather some data points from a few iOS devices:
iPad
- DPI: 264
- Diagonal Pixels: 2560
- Aspect Ratio: 1.333333
- Radius Variance: 5.21875
iPhone 12
- DPI: 460
- Diagonal Pixels: 2789
- Aspect Ratio: 2.164103
- Radius Variance: 6.065735
iPhone SE
- DPI: 326
- Diagonal Pixels: 1530
- Aspect Ratio: 1.778667
- Radius Variance: 6.411896
After recording a variety of touch inputs, it appears that Touch.radiusVariance = the difference between 2 sequential radii / 2.
Using the iPhone SE as an example, here are some possible Touch.radius sizes:
- 12.82
- 25.65
- 38.47
- 51.31
- 64.13
The difference between each sequential radius is roughly 12.82, which also happens to be the minimum Touch.radius size for this device. If we take that difference and divide it by 2 we get 6.41, or, if recorded with double precision, 6.411896, which is the radiusVariance for this device.
i.e., radiusVariance = (38.47 - 25.65) / 2.
I feel that I am getting closer to a solution but am still unsure of how Unity determines the Touch.radiusVariance as well as the possible Touch.radius sizes for a device. For now, I will be able to set the radiusVariance by referring to a constant variable after verifying the user’s device. However, I am a bit uncomfortable with this solution since there might be devices that do not fall into the categories of devices I have recorded. I would much rather be able to dynamically determine the radiusVariance of a device based on the specifications of that device.
In the meantime, I am currently exploring the radius.sqrMagnitude and radius.normalized of Unity’s new input system. There seems to be very little documentation on these properties, but from what I can tell:
- radius.sqrMagnitude = (radius.x * radius.x) + (radius.y * radius.y)
- radius.normalized = radius / (√radius.sqrMagnitude)
If I can use these properties to determine the sequential difference of radii or the minimum Touch.radius then I should be able to gather the Touch.radiusVariance as well.
I will continue researching and if I come across anything interesting I will be sure to post it here.