Problem with polygon collision detection.

Hy,
I’m trying to make an object to perform some activity while it’s touching another object - like ground.
Ground is made from polygons using PhysicsEditor.
I’m using this function for detecting collision.

local function onLocalCollision( self, event ) if ( event.phase == "began" ) then PERFORME ACTIVITY = TRUE elseif ( event.phase == "ended" ) then PERFORME ACTIVITY = FALSE end end

While the ball is rolling down the hill it’s touching ground, but i’m getting from event = ended.
Works fine with rectangle body, how can i’m make it work with polygon body?

Thanks
[import]uid: 177754 topic_id: 35592 reply_id: 335592[/import]

Hi @afffons,
Is your ground made up of several polygons pieced together? If at any point your rolling object exits the contact of any ground object, you’ll get an ended phase. Even if your rolling object is “on the ground”, if it leaves contact from one piece of the ground to another, you’ll get that ended phase. I’m not sure what your intention is, but there are some ways to control this better. You can sense how many pieces of the ground a rolling object is on at any given point, using a counter, for example.

If you have more questions, let me know.
Thanks,
Brent [import]uid: 200026 topic_id: 35592 reply_id: 141476[/import]

Here’s one way:

http://developer.coronalabs.com/code/physics-body-collision-location [import]uid: 8271 topic_id: 35592 reply_id: 141481[/import]

Thanks for reply,

Could you give me some example with counting objects?
Seems with this way - on event (“began” +1) and (“ended” - 1) works.
Is there some better way? [import]uid: 177754 topic_id: 35592 reply_id: 141589[/import]

Hi @afffons,
Yes, that’s the method I would suggest… and I would set that value as a property of the object, so it’s easy to track (versus another local variable floating around somewhere).

Also remember that if you’re dealing with a multi-body (many shapes put together into one), you’ll get a began and ended phase for each part of the body that makes/breaks a contact.

Brent [import]uid: 200026 topic_id: 35592 reply_id: 141602[/import]

Hi @afffons,
Is your ground made up of several polygons pieced together? If at any point your rolling object exits the contact of any ground object, you’ll get an ended phase. Even if your rolling object is “on the ground”, if it leaves contact from one piece of the ground to another, you’ll get that ended phase. I’m not sure what your intention is, but there are some ways to control this better. You can sense how many pieces of the ground a rolling object is on at any given point, using a counter, for example.

If you have more questions, let me know.
Thanks,
Brent [import]uid: 200026 topic_id: 35592 reply_id: 141476[/import]

Here’s one way:

http://developer.coronalabs.com/code/physics-body-collision-location [import]uid: 8271 topic_id: 35592 reply_id: 141481[/import]

Thanks for reply,

Could you give me some example with counting objects?
Seems with this way - on event (“began” +1) and (“ended” - 1) works.
Is there some better way? [import]uid: 177754 topic_id: 35592 reply_id: 141589[/import]

Hi @afffons,
Yes, that’s the method I would suggest… and I would set that value as a property of the object, so it’s easy to track (versus another local variable floating around somewhere).

Also remember that if you’re dealing with a multi-body (many shapes put together into one), you’ll get a began and ended phase for each part of the body that makes/breaks a contact.

Brent [import]uid: 200026 topic_id: 35592 reply_id: 141602[/import]