Set Gravity Error

WHERE AM I SUPPOSED TO POST QUESTIONS LIKE THESE??? <—so I know in the future

 

Unless I add event.yGravity the xGravity doesn’t work. But I don’t want the yGravity to be used when tilting. Think of it like I’d want to move like Doodle Jump.
 
Sorry, couldn’t get the code to enter in message with number lines so I just sent plain text   :frowning:
 
display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()

local player = display.newImage( “player.png” )
player.x = 160
player.y = 230
player.myName = “player”
physics.addBody( player, { friction=0.3, bounce = 5.0, density = 1.0, radius = 35 } )
player.isFixedRotation = true
system.setAccelerometerInterval( 100 ) – set accelerometer to maximum responsiveness

local ground = display.newImage( “ground.png” )
ground.x, ground.y = 160, 500

function onTilt( event )
physics.setGravity( ( 25 * event.xGravity ) )
end

 

Runtime:addEventListener( “accelerometer”, onTilt )

hi @kylefigula,

try setting your gravity y value to 0.

function onTilt( event ) physics.setGravity( ( 25 \* event.xGravity ), 0 ) end &nbsp;

burhan

It works but now I have the same problem as before, the player floats because its trying to use the gyroscope as y gravity instead of just pushing the player down to the ground :frowning:

Hi,

There may be other ways to do this but here is part of my tilt code from my recent game Diving Fairy (iOS).

physics.setGravity( 0, 0 ) -- set x & y gravity to 0 system.setAccelerometerInterval( 50.0 ) local tiltSpeed = 100 function onTilt( event ) movementX = tiltSpeed \* event.xGravity player.x = player.x + movementX -- prevent player moving offscreen if player.x \<= 30 then player.x = 30 elseif player.x \>= 310 then player.x = 310 end end Runtime:addEventListener( "accelerometer", onTilt )

burhan

There is a Physics specific sub-forum (http://forums.coronalabs.com/forum/109-physics/) for Physics questions, but here is okay.

Rob

Thank you sooooooo much!!! ;) I don’t have an IOS device except for the school provided macbook, so I’m sorry that I can’t get your game :frowning:

hi @kylefigula,

try setting your gravity y value to 0.

function onTilt( event ) physics.setGravity( ( 25 \* event.xGravity ), 0 ) end &nbsp;

burhan

It works but now I have the same problem as before, the player floats because its trying to use the gyroscope as y gravity instead of just pushing the player down to the ground :frowning:

Hi,

There may be other ways to do this but here is part of my tilt code from my recent game Diving Fairy (iOS).

physics.setGravity( 0, 0 ) -- set x & y gravity to 0 system.setAccelerometerInterval( 50.0 ) local tiltSpeed = 100 function onTilt( event ) movementX = tiltSpeed \* event.xGravity player.x = player.x + movementX -- prevent player moving offscreen if player.x \<= 30 then player.x = 30 elseif player.x \>= 310 then player.x = 310 end end Runtime:addEventListener( "accelerometer", onTilt )

burhan

There is a Physics specific sub-forum (http://forums.coronalabs.com/forum/109-physics/) for Physics questions, but here is okay.

Rob

Thank you sooooooo much!!! ;) I don’t have an IOS device except for the school provided macbook, so I’m sorry that I can’t get your game :frowning: