How to set up tilt input axis mappings for mobile devices?

I tried using Tilt, Gravity, Acceleration, and Rotation Rate as axis mappings in my input settings, but they don’t do anything when I test my game on my Nexus 5. What am I missing? How do I use my device’s rotation as input?

Can you give me a little details on how you tried to set them up?

If you were trying to bind them directly to the Axis Mappings then yeah, those aren’t going to work at the moment as the current Axis Mappings are single float value axes. I am planning on getting the vector axes bindable through the input components, hopefully for 4.2, but no promises.

Currently you should be able to use the PlayerController function GetInputMotionState to get the current values of each of the device motion vectors. If that is not working for you please let me know so we can take a closer look at it.

Yes, I was trying to bind them to the Axis Mappings. So I tried using GetInputMotionState via Blueprints but the values(Tilt, Rotation Rate, Gravity, Acceleration) always return 0.

same here. I tried using GetInputMotionState on my character’s player controller (GetPlayerController with index 0) and the values are always 0. I’m using blueprint. I feel like I’m probably not getting the right player controller, but I have the default PlayerController set in my GameMode and assume it should be accessible through my active pawn’s blueprint like I tried (the blueprint is receiving other input that I can move my character with).

Sorry for slow reply, as a result of this we discovered that the motion controls are not actually hooked up like we thought they were. This is being rectified.

I also went ahead and added the ability to bind Vector Axes to events in the InputComponent.

Apologies for the trouble.

thank you!!

When should we see this? 4.2?

any news on this? 4.2 I got it working by directly reading the InputKeyState, now in 4.3, nothing is working… gonna have to use the default virtual joysticks.


i’m using 4.2 and discovered the same problem. GetInputMotionState() always returns 0.
Can someone please try if this has been fixed in 4.3? Thank you very much!

A related question:
Is there a way to get the current device rotation in absolute values? I’m talking about the absolute rotation of the smartphone, not the new input force on the values.

4.3 not working. But performance is better on mobile it seems.


What device(s) are you experiencing this issue on in 4.3?

HI, I tried on the Galaxy Note 3 (ATC) and iOS 7, iPhone 4.

I’m able to output the tilt, etc. with 4.3 on iOS using both the PlayerController->GetInputMotionState and the PlayerController->GetInputVectorKeyState. However, as soon as a touch event is registered, all returned values are zeroed. I haven’t figured out how to re-enable them; it appears the touch input cannibalizes the motion input.

Edit: I was wrong. I had an invisible Touch Interface that was (probably) colliding with the GetInputMotionState results. After clearing the touch interface, I’m able to get consistent tilt data from PlayerController->GetInputMotionState.

Thanks for the answer. I’m now using 4.3 and still get 0 values from PlayerController->GetInputMotionState
piinecone, what did you do to get this working? I quickly created a new project, used the Add code to Project menu to add classes of GameMode and PlayerController. For the GameMode, i simple linked PlayerControllerClass to my PlayerController class. Inside my PlayerController, i just overrode Tick. At Tick(), i’m calling GetInputMotionState(Tilt, RotationRate, Gravity, Acceleration). Values are always 0 for me.

Did i forgot something?

//PS: i’m testing on android

Hi, I had the same 0 values on my Android ‘Note 10.1 2014’ and UE 4.3.
As a quick&dirty workaround i’am getting the gyro info directly from LaunchAndroid.cpp (line 440) thru a global variable.

             else if (ASENSOR_TYPE_GYROSCOPE == sensor_event.type)
					{ MyGlobalVariable_motionGyroscope.X = sensor_event.vector.pitch;
					MyGlobalVariable_motionGyroscope.Y = sensor_event.vector.azimuth;
					MyGlobalVariable_motionGyroscope.Z = sensor_event.vector.roll;

						current_gyroscope.X += sensor_event.vector.pitch;
						current_gyroscope.Y += sensor_event.vector.azimuth;
						current_gyroscope.Z += sensor_event.vector.roll;
						current_gyroscope_sample_count += 1;

It seems that the surrounding while loop is never ending, so the results are never calculated and send away.
Hope that helps.

Hi, i made a reply a few lines below. :slight_smile:

I found a better solution (but its still just a temp. workaround!) . I just put the result calculation into the never ending while loop.
In this way PlayerController->GetInputMotionState starts working in a ‘normal’ way.
Just replace AndroidProcessEvents in LaunchAndroid.cpp with the following code.
You can find the code on my UE branch. [1]:

Howdy everyone,

I have attempted to recreate the issues that have been occurring with builds on mobile devices and have been successful with Android builds. I have also tested this issue with iOS devices and have have ran into no such issue with the Tilt not showing correctly. Here is the setup that i was using to test the tilt functionality on:

I tested this on both the Samsung Galaxy Note 3 and the iPhone 4, iOS 7.0. The numbers where showing correctly for the iPhone, while the Note 3 was only showing zeroes. I have entered this issue into our bug database so the it may be fixed in a future release.

Thanks and have a great day!

Thank you, i hope it might be fixed soon. I think its not an issue with the Note 3, but with android devices in general. My Google Nexus 4 generates only zeroes, too. However, with the old 4.2 i’m now able to get tilt values by overriding InputMotion(). Still testing that out though, as that values seems to be not that useful for me.

For 4.3, it is impossible for me to get values other than zeroes.

FYI… I fixed the missing sensor values for 4.4 (this is the commit). You might be able to backport to your local 4.3. Or just wait for 4.4.