Hello guys
I am trying to use Android Input.Accelerometer, but there is a little problem.
With Unity 3.5.5 the accelerometer was correctly aligned with device, but with Unity 4 It looks aligned is portrait orientation of the device.
I mean I am using Landscape Mode, and -Input.accelerometer.y recognize as the device is tilted to left or to right when is tilted lanscape. When I tilt my device to portrait then it returns 0.
Is there any way to fix this problem, or to use 3.5.5 accelerometer settings?
Thanks. Byee.
hi i mostly fix the problem with the accelerometer when you use the ConstrainMotion script remove the X motion that improve the axis motion.
it work to me on IOS i hope he work on Android
Unity 4.0 release notes:
Android: Removed X<->Y axis mismatch for Android input. Now out of the box it should match iOS input. Requires code refactoring!
iOS: Now iOS sensors follow screen orientation. No more complicated code for axis remapping! This can be switched off via Input.compensateSensors. Requires code refactoring!
In short; the accelerometer should as of Unity 4 be aligned to the game view on both iOS and Android.
dragonstar: How do you do? I didn’t found that script. How does it works?
bitter: It looks the correct way, but there is one problem: Unity - Scripting API: Input.compensateSensors
(on Android compensation can't be turned off at the moment)
Any way to ignore this, and force Unity to turn off?
Thanks
hum, that looks wrong - most likely someone forgot to update the documentation during development. did you try setting it to false? it should work™
I tried, but it didn’t worked.
Hi, I just tried a small project on 4.0 and the Input.compensateSensors works as it should. What is your expected result? To clarify the functionality,
“Input.compensateSensors = true”
Y = up/down related to the gameview regardless device or orientation
X = left/right related to the gameview regardless device or orientation
“Input.compensateSensors = false”
Y = up/down related to the ‘natural orientation’ of the device
X = left/right related to the ‘natural orientation’ of the device
The ‘natural orientation’ is usually landscape for tablets and portrait for phones.
I have tried also with true and false. But the result was the same.
I also tried to put it as variable and update it in Update function.
The tablet which I am trying is Asus Nexus 7.
Should this be a problem of Unity Remote?
Oh, you are talking about the remote? Yes, in 4.0.x there is a bug which causes accelerometer input to be wrong for android - this was fixed in 4.1. The remote still doesn’t have support for Input.compensateSensors but we are working on fixing that for an upcoming unity release.
I have tried to build from Unity 4.1.0f4 with Input.compensateSensors true and false, but still have the same result.
If you hold the device in it’s natural orientation, landscape for Nexus 7, compensateSensors should not affect the values of the accelerometer. I just tested this locally with a nexus 7 and the values are correct.
If you hold the device flat - screen pointing up. Then x and y should be zero, z should be -1. If your game is in landscape mode and you tilt the device away from you or towards you according to the game view, Y should change to a positive or negative value. If you tilt the device sideways X should change.
Just to be clear, in 3.5 the accelerometer was mapped in a different way. So you have to change your code to make it fit 4.0.
Oh sorry!
Now I got it, To choose the correct axis I use to write on screen the Vector3 Input.acceleration. For my game the correct axis is x. Thanks you so much!
In Unity 4.1 is not working. Any solution? When I compile in 3.5 has no problems, but I made a stupid opening my project in Unity 4.1 and I have to finish the game on it. Someone has the same difficulty?
@eciosf, the accelerometer works fine on all devices we’ve tested so far. Can you please give a more detailed description of the problem you are experiencing? As have been pointed out previously if you are upgrading from 3.5 → 4.x you need to change your code to fit the new accelerometer mapping.
I have upgraded to 3.57 (latest 3) and my accelerometer wants to turn left all the time suddenly ? is this the same issue here please did something change on the 3.xx cycle ?
I just wondered why Android accelerometer suddenly behaved equal to iOS. A small but helpful feature. Thanks a lot!