Controlling gravity with RotationRate?

Is there a way to control the x-axis gravity with rotation rate? I want this to affect my physics bodies, which are circles, but whenever I try to plug in RotationRate.x into physics.gravity or GravityScale the app crashes.

@YoloSwag I’m not sure what you’re asking, but going by the title, here’s an example of RotationRate.x controlling the gravityScale. Tilt the iPad towards or away from you.


supportedOrientations(PORTRAIT)

function setup()
    parameter.watch("RotationRate.x")
    b=physics.body(CIRCLE,50)
    b.x=WIDTH/2
    b.y=HEIGHT
end

function draw()
    background(40, 40, 50)
    fill(255)
    ellipse(b.x,b.y,100) 
    b.gravityScale=RotationRate.x
end

@dave1707. Can gravityScale be used for the x-axis as well, so the ball would go sideways?

@YoloSwag If you use physics objects, gravity only goes down. You can make an object go sideways by changing the linearVelocity. Are you trying to control how an object moves by tilting the ipad in different directions.

@YoloSwag Are you after something like this. Hold the ipad flat and tilt it in the direction you want the circle to go.


displayMode(FULLSCREEN)

function setup()
    x=WIDTH/2
    y=HEIGHT/2
end

function draw()
    background(40, 40, 50)
    fill(255)
    ellipse(x,y,50)
    x=x+Gravity.x*10
    y=y+Gravity.y*10
end

@dave1707, gravity does not only go down.

try physics.gravity(Gravity.x * 10, physics.gravity().y) to control horizontal movement with tilting.

@JakAttak Thanks. For some reason I never tried using that. I now have something new to try.