Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3660970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:15:26+00:00 2026-05-19T01:15:26+00:00

The Android game My Paper Plane is a great example of how to implement

  • 0

The Android game My Paper Plane is a great example of how to implement tilt controls, but I’ve been struggling to understand how I can do something similar.

I have the following example that uses getOrientation() from the SensorManager. The whole thing is on pastebin here. It just prints the orientation values to text fields. Here is the most relevant snippet:

private void computeOrientation() {
    if (SensorManager.getRotationMatrix(m_rotationMatrix, null,
                                        m_lastMagFields, m_lastAccels)) {
        SensorManager.getOrientation(m_rotationMatrix, m_orientation);

        /* 1 radian = 57.2957795 degrees */
        /* [0] : yaw, rotation around z axis
         * [1] : pitch, rotation around x axis
         * [2] : roll, rotation around y axis */
        float yaw = m_orientation[0] * 57.2957795f;
        float pitch = m_orientation[1] * 57.2957795f;
        float roll = m_orientation[2] * 57.2957795f;

        /* append returns an average of the last 10 values */
        m_lastYaw = m_filters[0].append(yaw);
        m_lastPitch = m_filters[1].append(pitch);
        m_lastRoll = m_filters[2].append(roll);
        TextView rt = (TextView) findViewById(R.id.roll);
        TextView pt = (TextView) findViewById(R.id.pitch);
        TextView yt = (TextView) findViewById(R.id.yaw);
        yt.setText("azi z: " + m_lastYaw);
        pt.setText("pitch x: " + m_lastPitch);
        rt.setText("roll y: " + m_lastRoll);
    }
}

The problem is that the values this spits out look like nonsense, or at least there’s no way to isolate which type of motion the user performed. I’ve drawn a diagram to indicate the 2 types of motion that I’d like to detect – 1. “tilt” for pitch and 2. “rotate” for roll/steering:

Figure 1. Pitch and roll

(That’s an isometric-ish view of a phone in landscape mode, of course)

When I tilt the phone forwards and backwards along its long axis – shown by 1. – I expected only 1 of the values to change much, but all of them seem to change drastically. Similarly, if I rotate the phone about an imaginary line that comes out of the screen – shown in 2. – I’d hope that only the roll value changes, but all the values change a lot.

The problem is when I calibrate my game – which means recording the current values of the angles x, y and z – I later don’t know how to interpret incoming updated angles to say “ok, looks like you have tilted the phone and you want to roll 3 degrees left”. It’s more like “ok, you’ve moved the phone and you’re a-tiltin’ and a-rollin’ at the same time”, even if the intent was only a roll. Make sense?

Any ideas? I’ve tried using remapCoordinateSystem to see if changing the axis has any effect. No joy. I think I’m missing something fundamental with this 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:15:27+00:00Added an answer on May 19, 2026 at 1:15 am

    You mixed the accelerator and megnetic sensor arrays. The code should be:

    if (SensorManager.getRotationMatrix(m_rotationMatrix, null,
                                        m_lastAccels, m_lastMagFields)) {
    

    Check out getRotationMatrix(..)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie to android game development. I've been trying an example of game
I'm making a fast-paced realtime Android game, and everything works great, but the first
i'm developing a android game which uses libgdx and bullet physics engine. I can
I am creating an android game where enemies are generated randomly and there can
In my Android game I detected the collision of a ball and line, but
Ive been working on multiplayer android game that sends locally stored data to a
I'm working on an android game and have been considering my main game loop.
I have been working on an Android game for the past 6 months or
I want to save my Android game state so the user can pick up
I am developer of Android game. I have create an GLSurfaceView and draw something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.