Collision detection on a physics object not working.

Hi guys. This is only my 3rd day of using Corona and love it, however I've run into an issue.

I'm trying to create a complex physics object, however, for some reason whenever the player walks over it, about half way through they fall through..

Now I'm thinking its due to how I entered the coordinates (clockwise notation), but I've tried changing them around and doing them backwards but no luck. Its just a rectangle, so, it shouldn't have any concave issues. Any tips?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--add the ground
local ground1 = display.newImage("ground1.png")
game:insert(ground1)
 
 
local physics_body = {}
physics_body["ground1"] = {
                        
                                {
                                        density = 5.0, friction = 0.5, bounce = 0.3, 
                                        shape = {400,200, 400,220, 0,220, 0,200}
                                }
                        }
                        
physics.addBody(game, "static", unpack(physics_body["ground1"]))

First, turn on physics debug:
physics.setDrawMode( "debug" )

Then, I believe you need to define your shape boundry "from the centroid of the object".

Oh, yes I have all that.

1
2
3
4
5
-- Activate physics engine
local physics = require("physics")
physics.start()
physics.setGravity(0.3,9.8)
physics.setDrawMode("hybrid")

Correct. This is one of the early issues I ran into. Box2d engine evidentally assumes all objects have a center reference point. So a box 100 width and height will be defined as -50, -50 and 50, 50. Give that a go.

views:1323 update:2011/10/4 17:12:07
corona forums © 2003-2011