Detecting 360 motion on mobile (Android, Unity3D)

Started by
2 comments, last by Volvary 8 years, 3 months ago

Hey everyone, Volvary here.

As some might have seen recently, I've been working for a little while on an Android game with sound and rotation as the main components for input/output.

Well, one of those mechanic has given me quite the mental workout and that is the rotation.

So first off, I will be explaining what I mean by rotation. What I want to achieve is what could be described as AR (Augmented Reality). Think of it as the phone acting as a "window" to the game world. By moving the phone around, you would be able to move your view inside the game and see what hides in that direction.

I have tried multiple things but I can't seem to get it to work.

So in order:

First I tried rotating my camera by Input.acceleration. By itself, it gave off something very imperceptible. Scaled to greater sensibility, it revealed to be detecting 2-5 motions a frame even with the phone laid on a surface, causing sporadic movements.

Then I tried Input.gyro (making sure to activate it). But whatever I tried, I couldn't get any value to display anything else than 0. (Does the phone I am testing on has a gyro? I have no idea, I still suck when it comes to mobile dev)

The thing is I'm pretty sure it can be done. (And with only the accelerometer, if I'm not wrong, making it stable) But I'm dumbfounded as to why it failed. And since I don't know the proper term for what I'm trying to do, I can't find a single piece of information that can help me right now.

There are 10 types of people in the world: Those who understand binary, those who don't and those who didn't expect this to be in tertiary.

Advertisement
I've never used it before, but this sort of sounds like what you want (Rotation Vector Sensor):

http://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-rotate

There is also one specific to games that you might try:

http://developer.android.com/guide/topics/sensors/sensors_position.html#sensors-pos-gamerot


The first one appears to use the Earth's magnetic field as a reference, and the second is likely integrating gyro data.

The thing is I'm pretty sure it can be done. (And with only the accelerometer, if I'm not wrong, making it stable)

It can be done, but you will have a really hard time trying to do it with just the accelerometer.

The main problem with using earth gravity as a reference for which way you are facing is that the vector points the wrong way! Since it points down, you have no way of knowing the difference between looking north and looking south. (or any other direction)

You will need more sensors.

As you have also noticed, the sensors is generally pretty noisy, you will never get an exact value from it, but they need to be smoothed over several frames.

This on the other hand might make the movement sluggish.

Thats another reason to use more then one type of sensor, they can cancel out each others errors making the end result more stable, if combined in the right way.

A better idea than to try to solve this yourself (It's not an easy problem), could be to use an API where the motion sensors have already been integrated to an orientation
Nypyren has linked to such APIs.


The thing is I'm pretty sure it can be done. (And with only the accelerometer, if I'm not wrong, making it stable)

It can be done, but you will have a really hard time trying to do it with just the accelerometer.

The main problem with using earth gravity as a reference for which way you are facing is that the vector points the wrong way! Since it points down, you have no way of knowing the difference between looking north and looking south. (or any other direction)

You will need more sensors.

As you have also noticed, the sensors is generally pretty noisy, you will never get an exact value from it, but they need to be smoothed over several frames.

This on the other hand might make the movement sluggish.

Thats another reason to use more then one type of sensor, they can cancel out each others errors making the end result more stable, if combined in the right way.

A better idea than to try to solve this yourself (It's not an easy problem), could be to use an API where the motion sensors have already been integrated to an orientation
Nypyren has linked to such APIs.

Oh, I see.

Thanks to both of you, I will be trying to apply what you just brought up to me and see if I can make it work. I'll be updating relating to what I manage to do.

There are 10 types of people in the world: Those who understand binary, those who don't and those who didn't expect this to be in tertiary.

This topic is closed to new replies.

Advertisement