Search code examples
mobileunreal-engine4

Pinch and Rotate Events are called at the same time no matter finger position in Unreal?


Basically, I am creating a mobile app in Unreal. I found that Unreal has built in Rotate and Pinch gestures for mobile phones. However, about five seconds after I discovered them I once again fell into the abyss that is despair.

After attaching just a simple print string to both events I found that no matter how I place my fingers on the screen both events are called basically at the same time. Setting up simple Booleans for each event I found that the pinch event basically wins out in this input battle 9/10 times.

I feel like I'm not doing anything wrong as far as programming goes considering it is a built in event. Is this some sort of bug or is it broken? Is there some specific way my fingers have to move in order to call one event or the other? I feel like I did the pretty standard pinch and rotate gesture for mobile phones...


Solution

  • After doing some more research I found that after setting up an axis value for the two gesture events, they both give very different values. The pinch gesture gives a value consistently between 0 and 14ish. On the other hand the rotate gesture axis returns a degree of rotation.

    I solved the issue of both of them performing at the same time by caching the current rotation axis value and checking it against the next value if the difference between the two was greater than 10 (Absolute value) then I performed a rotate, I also took that value and divided it by 5 to get a smoother rotation, 2 degrees per call.

    As far as the pinch axis goes, I didn't feel the need to put a limiter on it because my zoom speed is relatively slow and for the most part when performing the rotate the value doesn't change very much. However, if anyone plans on using the pinch gesture, I highly recommend normalizing the range between -1 and 1. I think it is just poor execution on Unreal's part that it doesn't do this out of the box. A little suggestion on how to do this is that you'll have to check if the value is greater than 1 (Zoom in) or not (Zoom out). So you have to normalize the values from 0-1 to -1 to 0 and the values 1-14 to 0 to 1 if that makes sense. Considering that the pressed event is called every tick that two fingers are on the screen it just makes sense to normalize the values. Of course if you're just replacing the scale with the axis value then it works out of the box but, most people don't scale the objects up they just move the camera/boom forward or smaller.

    I hope this helps somebody else trying to use these poorly documented gesture events.