playMaker

Author Topic: tilt control in android without a gyroscope  (Read 699 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
tilt control in android without a gyroscope
« on: July 31, 2021, 06:53:20 PM »
While working on my own project I wanted to add tilt control, unfortunately, my old phone and many other types of mobile phones do not support gyroscope control. So in my example, I use the "Get Device Acceleration Action".

In this example FSM, I am able to use the action to successfully move the object within constraints moving both left and right.

Here is a screenshot of the FSM: https://ibb.co/XpLnkHh

 The Float value within the "Float Compare" may need to be adjusted to suit your play area.

The multiplier value within the "Get Device Acceleration Action" has been set to 35 as that level feels right for me on my phone.

I couldn't quite fit the remaining part of the "Translate Position 2D" action.

Within the float X movement in the axis use variable "X_tilt" with both per second and every frame checked.

In order to actually test this, you will need to have your project set as "Andriod build" and use "Unity Remote".

When played on your device, hold the phone upright, now tilt left and right to move the object.

The object will move left or right and stop according to the stop values.

My issue is that I am trying unsuccessfully to use the same action, but move a similar object up and down.

With my current setup, it does work; but only with the phone laying down flat.

Following feedback from a c# developer, he said "You have to calibrate the initial rotation (offset) of the phone. Otherwise, it only works when the phone is lying down flat, which is not how anyone holds their phone. So store the initial values of the tilt while in the menu, then subtract that from the input while playing.

But to be honest I am lost at this point and require your help and insight.

Kind regards

Colpolstudios