How to define our object in physics engine...?

Hi guy,

I am new in Corona and still learning this awesome framework. Just a simple question maybe takes you 1 min to answer. I khow how to create an object and add it to physics body like this, but if an object is not a perfect geometric shape like a circle or square or rectangle, I have an issue. It seems there is a invisble rectungle around my PNG file that does’t let the object to stay in natural physics bahavior.

For exmple, see the screenshot. Why the house stayed like this? when I drag it and move it, it seems it’s inside a square.

this is the code that creates it:

the code is in :  Sample Code\Physics\DragPlatforms

local cube = display.newImage( "house\_red.png", 80, 150 ) physics.addBody( cube, { density=5.0, friction=0.3, bounce=0.4 } )

What I mean is the house should not stay like this, it should fall to the right or left ( in real life object )

Should I change anything in PNG file or in the code ?

Thank you so much

You’re are probably looking for a 3rd party physics editor.
You can use them to make custom physics outlines of your objects.

The reason your ‘house’ object isn’t falling to either side is because it is indeed a rectangle. To better see what’s going on use this view mode:
physics.setDrawMode( “hybrid” ) --overlays collision outlines on normal display objects

-Saer

Some good 3rd party editors are:
physicseditor
SpriteHelper

– I know there are more, I just can’t think of 'em at the moment. –

and a few sprite-sheet/image sheet generator are:

texturepacker

I personally use LevelHelper - level editor - SpriteHelper - sprite-sheet/image sheet packer - and Animo Code.
I really like 'em all: http://www.gamedevhelper.com/

http://www.coronalabs.com/resources/3rd-party-tools-and-services/
 

Thank you Saerothir, I addd physics.setDrawMode( “hybrid” ) , yes you are right, the house is a rectangle, that’s why it doesn’t fall to left or right.

In this case, should I use a 3rd party editor like PhysicsEditor?

I am not sure if the following is possilbe, please see this page:

docs.coronalabs.com/guide/physics/physicsBodies/index.html

in Polygonal Bodies section, we can define the coordinate of our object, in a table variable and pass it to the “shape” parameter of “addBody”.

Thank you for the links you gave me, I will try them :slight_smile:

Andy

You could use PE. I personally have not used it before, but I do know of a few people who do and they like it.

I looked at the page, and yes that’s a perfectly valid method… I just never wanted to bother with it so I got a program instead. :wink:

As far as LevelHelper, and SpriteHelper and Animo code are concerned, they are great!
I’ve heard you can use SpriteHelper by itself, but really it was made to work in conjunction with LevelHelper - so in your case it might not be the best option.
Animo Code on the other hand is nothing more than a IDE for working with your project. It’s very clean and has some decent features.

It all comes down to what is best for you and your project.

Cheers!

-Saer

Edit: Unless you are making a game that will have a lot of physics objects, with unique collisions 'n such, you really don’t have to worry about buying/downloading a 3rd party application for handling your graphics. (my opinion anyway.)

I tried the method I said above and it worked. 

local house = display.newImage( "house.png" ) triangle.x = 200 triangle.y = 150 --define the shape table, this is four points of house local houseShape = { 0,-35, 37,30, -37,30, -40,-20 } physics.addBody( house, { shape=houseShape, density=1.6, friction=0.5, bounce=0.2 } )

I am using Lua Glider, so far it’s fine. I am still learning Corona… for now I’m working with simple physics api.

Thank you,

Andy

You’re are probably looking for a 3rd party physics editor.
You can use them to make custom physics outlines of your objects.

The reason your ‘house’ object isn’t falling to either side is because it is indeed a rectangle. To better see what’s going on use this view mode:
physics.setDrawMode( “hybrid” ) --overlays collision outlines on normal display objects

-Saer

Some good 3rd party editors are:
physicseditor
SpriteHelper

– I know there are more, I just can’t think of 'em at the moment. –

and a few sprite-sheet/image sheet generator are:

texturepacker

I personally use LevelHelper - level editor - SpriteHelper - sprite-sheet/image sheet packer - and Animo Code.
I really like 'em all: http://www.gamedevhelper.com/

http://www.coronalabs.com/resources/3rd-party-tools-and-services/
 

Thank you Saerothir, I addd physics.setDrawMode( “hybrid” ) , yes you are right, the house is a rectangle, that’s why it doesn’t fall to left or right.

In this case, should I use a 3rd party editor like PhysicsEditor?

I am not sure if the following is possilbe, please see this page:

docs.coronalabs.com/guide/physics/physicsBodies/index.html

in Polygonal Bodies section, we can define the coordinate of our object, in a table variable and pass it to the “shape” parameter of “addBody”.

Thank you for the links you gave me, I will try them :slight_smile:

Andy

You could use PE. I personally have not used it before, but I do know of a few people who do and they like it.

I looked at the page, and yes that’s a perfectly valid method… I just never wanted to bother with it so I got a program instead. :wink:

As far as LevelHelper, and SpriteHelper and Animo code are concerned, they are great!
I’ve heard you can use SpriteHelper by itself, but really it was made to work in conjunction with LevelHelper - so in your case it might not be the best option.
Animo Code on the other hand is nothing more than a IDE for working with your project. It’s very clean and has some decent features.

It all comes down to what is best for you and your project.

Cheers!

-Saer

Edit: Unless you are making a game that will have a lot of physics objects, with unique collisions 'n such, you really don’t have to worry about buying/downloading a 3rd party application for handling your graphics. (my opinion anyway.)

I tried the method I said above and it worked. 

local house = display.newImage( "house.png" ) triangle.x = 200 triangle.y = 150 --define the shape table, this is four points of house local houseShape = { 0,-35, 37,30, -37,30, -40,-20 } physics.addBody( house, { shape=houseShape, density=1.6, friction=0.5, bounce=0.2 } )

I am using Lua Glider, so far it’s fine. I am still learning Corona… for now I’m working with simple physics api.

Thank you,

Andy