app physics not working

when I run the program, the ship object always goes up instead of down. adding physics.setGravity doesn’t help. can I have some help?

here is the code (not permitted to upload sublime text file):

local physics1 = require(“physics”)
physics.start()
physics.setGravity( 0, 9.8 )

local ground = display.newImage(“ground.png”)
ground.x = display.contentWidth/2
ground.y = 340

physics.addBody(ground, {friction = .5})
ground.bodyType = “static”

local ship = display.newImage(“Space_Ship_Furniture.png”)
ship.x = display.contentWidth/2
ship.y = 340
ship.xScale = .06
ship.yScale = .06
 

physics.addBody( ship, { density = 2.0, friction = 0.5, bounce = 0.3 } )

Try making your ship object heavier.
I don’t use gravity in my game, but I do set my object’s density to 10000 so they don’t move around when they hit other objects.
Probably a bit extreme for your case, but nevertheless try increasing the density.

-Saer

update: I got it to fall down, except now it doesn’t bounce off the ground object. help?

Increase the ‘bounce’ value.

it goes straight through the ground, so the increasing the bounce didn’t help either.

Try this: physics.addBody( ship, “dynamic”, { density = 2.0, friction = 0.5, bounce = 0.3 } )

doesn’t work

Well it should. Try adding the ground’s bodyType in-line rather than post.
physics.addBody(ground, “static”, {friction = .5})

And again, try playing with the ship’s physics values.

now it is flying up again

What is the density of the ship object?

You must have code else where that is causing this to happen.
This code works perfectly fine:
[lua]
local physics = require (“physics”)
physics.start()
physics.setGravity( 0, 9.8 )

local ground = display.newRect(0, 0, 1024,10)
ground.y = display.contentHeight/2
physics.addBody(ground, “static”, {friction = .5})
 

local ship = display.newRect(0,0,50,50)
ship.x = display.contentWidth/2
ship.y = 0
physics.addBody( ship, { density = 2.0, friction = 0.5, bounce = 0.5 } )
[/lua]

Edit: Also, this is helpful for when you are trying to work with physics objects:
physics.setDrawMode( “hybrid” ) – overlays collision outlines on normal Corona objects
 

Try making your ship object heavier.
I don’t use gravity in my game, but I do set my object’s density to 10000 so they don’t move around when they hit other objects.
Probably a bit extreme for your case, but nevertheless try increasing the density.

-Saer

update: I got it to fall down, except now it doesn’t bounce off the ground object. help?

Increase the ‘bounce’ value.

it goes straight through the ground, so the increasing the bounce didn’t help either.

Try this: physics.addBody( ship, “dynamic”, { density = 2.0, friction = 0.5, bounce = 0.3 } )

doesn’t work

Well it should. Try adding the ground’s bodyType in-line rather than post.
physics.addBody(ground, “static”, {friction = .5})

And again, try playing with the ship’s physics values.

now it is flying up again

What is the density of the ship object?