Gravity on rotation

Hi

I assume the simulator can be used to test gravity when you rotate left and right?

I have simple project where I want balls to respond to gravity when the device is rotated. 

I have the following touch event but the balls keep falling to the bottom of the screen no matter what rotation…

function moveCoin(event)

    local ball = event.target

    ball:applyLinearImpulse(0, 2, event.xGravity, event.yGravity)

end

Hi @andrew085,

You’ll need to test accelerometer functionality on the device. Also note that accelerometer events are based on portrait orientation, so if you’re designing a landscape app, you’ll need to “adjust” the values according to landscape.

These details are discussed in the documentation:

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

Best regards,

Brent

Hi

I assume the simulator can be used to test gravity when you rotate left and right?

I have simple project where I want balls to respond to gravity when the device is rotated. 

I have the following touch event but the balls keep falling to the bottom of the screen no matter what rotation…

function moveCoin(event)

    local ball = event.target

    ball:applyLinearImpulse(0, 2, event.xGravity, event.yGravity)

end

I use http://www.coronaremote.com to simulate rotation/tilt in my apps.  You buy the iOS app and then include the listener file into your project.

local isSimulator = "simulator" == system.getInfo("environment") if isSimulator then local remote = require("remote") remote.startServer( "8080" ) remote.startCompass() end

I have added this to my on tilt event 

 if isSimulator then -- Running on Simulator xGravityLast = remote.xGravity yGravityLast = remote.yGravity zGravityLast = remote.zGravity if remote.isShake then DoPrint( "The device is being shaken!" ) AppShaken = True end else -- Running on Device zGravityLast = event.zGravity xGravityLast = event.xGravity yGravityLast = event.yGravity if event.isShake then DoPrint( "The device is being shaken!" ) AppShaken = True end end

The my code later can read single variables that a re fed from the iOS device via the corona remote while on a simulator or the real device when not on the simulator.

The only catch is you can rotate your real device while your app is running in the simulator and the balls will move but corona simulator will not rotate to match (but the data will get into your app). 

Hi @andrew085,

You’ll need to test accelerometer functionality on the device. Also note that accelerometer events are based on portrait orientation, so if you’re designing a landscape app, you’ll need to “adjust” the values according to landscape.

These details are discussed in the documentation:

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

Best regards,

Brent

Hi

I assume the simulator can be used to test gravity when you rotate left and right?

I have simple project where I want balls to respond to gravity when the device is rotated. 

I have the following touch event but the balls keep falling to the bottom of the screen no matter what rotation…

function moveCoin(event)

    local ball = event.target

    ball:applyLinearImpulse(0, 2, event.xGravity, event.yGravity)

end

I use http://www.coronaremote.com to simulate rotation/tilt in my apps.  You buy the iOS app and then include the listener file into your project.

local isSimulator = "simulator" == system.getInfo("environment") if isSimulator then local remote = require("remote") remote.startServer( "8080" ) remote.startCompass() end

I have added this to my on tilt event 

 if isSimulator then -- Running on Simulator xGravityLast = remote.xGravity yGravityLast = remote.yGravity zGravityLast = remote.zGravity if remote.isShake then DoPrint( "The device is being shaken!" ) AppShaken = True end else -- Running on Device zGravityLast = event.zGravity xGravityLast = event.xGravity yGravityLast = event.yGravity if event.isShake then DoPrint( "The device is being shaken!" ) AppShaken = True end end

The my code later can read single variables that a re fed from the iOS device via the corona remote while on a simulator or the real device when not on the simulator.

The only catch is you can rotate your real device while your app is running in the simulator and the balls will move but corona simulator will not rotate to match (but the data will get into your app).