Accelerometer ontilt does not work properly in lanscaperight setting ? please advise

any idea team in this question, 

Regards

Abdul

Brent really needs to chime in on this since he’s more Physics that me, but I would think the physics simulation would not like having gravity changed that often.  And I’m not sure that’s going to give you the effect you want anyway.

You’re only going to get the balls to stop moving when the device is perfectly flat.  You have to tilt it away from  you to move things up.  This would be pretty uncomfortable for a player to do.  You need to take the delta numbers from that and apply the results as some impulse or force to your balls.

Thanks Rob for your comments, 

Do you have similar example or tutorials that might help in this.

I will wait for Brent as well to comment in this. I am wondering why the behavior is different between portrait and landscape layouts.

Regards

Abdul

Hi Abdul,

I confirmed with the engineers, and essentially, the accelerometer values are always relative to portrait on both iOS and Android. So, if your app is landscape, you’ll need to compensate by 90 degrees.

See the documentation here:

http://docs.coronalabs.com/daily/api/event/accelerometer/xGravity.html

Best regards,

Brent

Hi Brent,

When you say " you’ll need to compensate by 90 degrees", Do you mean to add 90 to both x and y gravity as follow

[lua]

physics.setGravity( ( 9.8 * event.xGravity +90  ), ( -9.8 *event.yGravity +90 ) )

[/lua]

Regards

Abdul

Hi Abdul,

You’ll probably need to experiment. It may be +90 or -90 depending on if you’re using LandscapeLeft or LandscapeRight orientation.

Hi Brent ,

Actually I tried all the combination but no luck… i am using landscapeRight orientation … here are what I tried

[lua]
physics.setGravity( ( 9.8 * event.xGravity -90), ( -9.8 *event.yGravity ) )

physics.setGravity( ( 9.8 * event.xGravity +90), ( -9.8 *event.yGravity ) )

physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 *event.yGravity - 90) )

physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 *event.yGravity +90) )

physics.setGravity( ( 9.8 * event.xGravity -90), ( -9.8 *event.yGravity -90) )

physics.setGravity( ( 9.8 * event.xGravity +90), ( -9.8 *event.yGravity +90) )

physics.setGravity( ( 9.8 * event.xGravity -90), ( -9.8 *event.yGravity +90) )

physics.setGravity( ( 9.8 * event.xGravity +90), ( -9.8 *event.yGravity -90) )

[/lua]

Hi Abdul,

It’s not so much a direct “90” or “-90” application to the value. Instead, you need to effectively make the Y gravity be the X gravity, and possibly negate the value too. For example, if you had -9.8 m/s² being applied from the top (in portrait), and you rotate the device, that value is now being applied to the left (or right) of that object in regards to the accelerometer. So, you need to swap those values so that it’s being applied to the “new top” of the object in landscape.

Hi Brent ,

Finally I managed to get working with following line, 

[lua]

physics.setGravity( ( -9.8 * event.yGravity ), ( -9.8 *event.xGravity ) )

[/lua]

i swapped event.yGravity with event.xGravity and negate the event.xGravity… I am not sure I understand the concept behind it but it works… also i changed the number from 9.8 to 15 for both side just to make it move faster … I think Corona SDK should understand the landscape changes without changing the code since corona can understand the landscape and portrait orientation. This is my personal opinion. I might be wrong but I really struggled getting it to work because every change must do a build and test it in a real device as simulator cant show you the result of tilt event,

Regards

Abdulaziz