4
\$\begingroup\$

Does anyone know how to get the getPressure function from the Android API into Unity? Or is there another way I can access the pressure of a touch?

\$\endgroup\$
2
  • \$\begingroup\$ I would not think that this is natively supported, but have you seen this? You'll probably want to explicitly target devices. \$\endgroup\$
    – Vaillancourt
    Commented Mar 26, 2015 at 16:44
  • \$\begingroup\$ Thanks @AlexandreVaillancourt. I tried to follow your link, and i only got value from simple funtion. However, I still cannot access to touch event there from unity. :( \$\endgroup\$ Commented Mar 26, 2015 at 23:08

2 Answers 2

2
\$\begingroup\$

Short answer: This doesn't do what you think it does.

float pressure - A normalized value that describes the pressure applied to the device by a finger or other tool. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), although values higher than 1 may be generated depending on the calibration of the input device.

The float getPressure(int PointerId) method is a getter method for the float pressure instance variable of the MotionEvent.Pointer class. It returns a float between 0 and 1 which represent the 'pressure' from the accelerometer.

The value passed to the function is the id for the pointer (finger?) on the screen. For screens that support multi-touch you will probably want to check each finger/id. You can acquire the id from the event.getPointerId(index) object passed to a MotionEvent listener.

I do not know Unity myself as I avoid using it. However, you should be able to register an event listener for MotionEvent which is passed an event from which you can call event.getPressure(index) where index is between 0 and event.getPointerCount() - 1 and correspond to each 'finger' or touch point.

When you handle your touch events you can also call event.getPressure(index) for the [pointer]index your are handling the event for.

From my understanding of the documentation, it doesn't return how much pressure but rather that pressure was applied. This means that the only information you will garner from calling this is that a pointer event did indeed occur, which you already knew if you were handling it.

It seems this may be related to calibration. The screen can be calibrated to require more or less 'pressure' for a 'touch' event to be triggered.

Additional Information: This does indeed use the accelerometer to register the value stored in float pressure. What it does is when a finger touches the screen it detects whether or not the device accelerated along the axis that intersects the screen. In other words, when you touch the screen you ever so slightly cause your device to move back. This minute movement may be detected and when it is sets your pressure value for that particular touch. For this reason it may be wise to not rely on the data. I would suspect that if a device is flat on a non-movable/non-moving surface (such as a table or counter) then it probably wouldn't detect this. The device would still detect the touch and trigger the MotionEvent listener but the value gotten from getPressure() would probably be 0 and therefor meaningless.

A bit of additional history and the reason that this method exists. Android, and I suppose Apple, intended or at least hoped that pressure touch interface would be possible. However there, at the time, was no easy way to implement such a device. There are, however, external devices which will return more relevant data (such as a Bluetooth touch pad the touch region detection). I am not positive whether it uses this, but there are now devices coming out that have keyboards that literally rise and fall from the glass. I suspect that this may also use pressure sensitivity.

Finally, this question is a duplicate of this : https://stackoverflow.com/questions/12414491/getpressure-always-returning-1-0

\$\endgroup\$
1
\$\begingroup\$

Unity has had a Touch.pressure feature on supported devices since Unity 5.3. However, you will find that very few devices have pressure-sensitive screens.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .