objects and physics

I am looking for a way to allow the user to control an object with the accelerometer that is able to be calibrated so that the user doesn’t have to tilt the device completely away from themselves to move the object along the y axis.

I have tried setting the gravity to various degrees of negative values, but this doesn’t work correctly (I.E., the object ‘floats’ to the top of the screen and gets stuck there, or something in between that and just leaving the values at 0)

Any help would be greatly appreciated. [import]uid: 102017 topic_id: 17877 reply_id: 317877[/import]

You would probably need to figure out the the “zero point” for the devices orientation that you want to start from and then make your calculations from there. You could probably use the accelerometer sample code here http://developer.anscamobile.com/content/accelerometer-1
Just hold the device in the position you would like the player to start from and write down the accelerometer data that is shown on the screen and use that as your starting point for gravity to be set to 0, then apply positive or negative gravity depending on the direction of the tilt from there. [import]uid: 27965 topic_id: 17877 reply_id: 68287[/import]

I have tried several variations of how I am interpreting your solution, which sounds correct to me as well.

Any idea how to use the desired state of gravity as “0” gravity? If I simply subtract it from the base gravity I end up with negative gravity which causes objects to ‘float;’ though perhaps editing the physical attributes of the objects would prevent this.

hm…

thanks for the input. [import]uid: 102017 topic_id: 17877 reply_id: 68659[/import]

First of all I just want to say Thank You! It’s awesome that you tried a bunch of different things before asking for help again. You will learn a lot that way.

Have you tried an if statement to check if the gravity is above or below a certain point? For example, lets say that the accelerometer gravity you want to be “0” gravity is 100, so anything above that you want to apply gravity but anything below means no gravity (which hopefully will eliminate float).

[lua]function onTilt( event )
if event.yGravity >= 100 then
physics.setGravity( 0, ( -9.8 * event.yGravity ) )
else
physics.setGravity( 0, 0 )
end

Runtime:addEventListener( “accelerometer”, onTilt )[/lua]
If this isn’t what you where talking about could you post some code so I can get a better idea of what you’re trying to do?
[import]uid: 27965 topic_id: 17877 reply_id: 68670[/import]

Thanks again for all of your help.

After playing around with the code you provided for a while (which works great for it’s intended purpose) it occurred to me that the real problem is not calibrating the gravity, but that I am using gravity at all (since objects affected by gravity will behave as if there were real gravity).

The solution that I have come up with was to use a different method, which was to reference event.yInstant instead. That way I am getting information about the tilt of the device but am not limited by the effects of gravity on an object. [import]uid: 102017 topic_id: 17877 reply_id: 68765[/import]

That’s great! Wow I didn’t even consider that, thanks for sharing your solution. Might come in handy for one of my future projects. [import]uid: 27965 topic_id: 17877 reply_id: 68770[/import]