[Resolved] Why won't these physics objects collide? [SOLVED]

This is driving me crazy. I see the two physics objects are registering, but the player will not collide with the green box. I got the physics for the map that the player can successfuly run on from PhysicsEditor and the physics for the square plant tile from Tiled and I am using lime. Why won’t a collision register with the plant tile, even though it clearly shows up?

some_text

Thanks. I am wondering if Lime is using a ‘physics filter’ or something,and if so, how can I get rid of it?

Thanks [import]uid: 59735 topic_id: 33195 reply_id: 333195[/import]

It could be a filter situation. Also, if a physics body has “.isSensor = true” then the collision will register but the objects will pass thru each other. That sounds a little bit like what you’re describing.

Hope this helps. [import]uid: 136211 topic_id: 33195 reply_id: 131861[/import]

Thanks, and It is not a sensor. Do you know if I could remove the filter? [import]uid: 59735 topic_id: 33195 reply_id: 131868[/import]

You mentioned using Lime, which I’ve never really gotten in to. Not sure how physics bodies are set-up using Lime but I create mine (with filters) using this method:

https://developer.coronalabs.com/forum/2010/10/25/collision-filters-helper-chart

If Lime does apply an unwanted filter, I’m not 100% how to remove it after the object’s already been created. I wonder if something like “body.filter = nil” would work. [import]uid: 136211 topic_id: 33195 reply_id: 131873[/import]

So I was curious and researched a little more myself. It looks as though you aren’t able to change a filter once the object’s body has been created. They recommend removing the body and making another. I saw this here:

http://developer.coronalabs.com/forum/2010/11/08/changing-collision-filters-after-physics-object-created

Granted, the post is a tad old. But just wanted to point it out.

Good luck! [import]uid: 136211 topic_id: 33195 reply_id: 131875[/import]

Are you using more than 8 points in a custom shape? The bodies have lines running through them and I’m wondering if your setup is a little off. Any code for assigning bodies? (Or are they just multiple bodies stacked on top of each other?)

Peach :slight_smile: [import]uid: 52491 topic_id: 33195 reply_id: 131878[/import]

Actually, the bodies where created using physicsEditor, and that was just a poor autotrace.

Interesting, I searched through the Lime module code and found this function which I commented out.
[lua]function addCollisionFilterToBody(item)
–[[
local _item = item

local categoryBits = _item:getPropertyValue(“categoryBits”)
local maskBits = _item:getPropertyValue(“maskBits”)
local groupIndex = _item:getPropertyValue(“groupIndex”)

if(categoryBits or maskBits or groupIndex) then

local collisionFilter = {}

collisionFilter.categoryBits = categoryBits
collisionFilter.maskBits = maskBits
collisionFilter.groupIndex = groupIndex

_item.filter = collisionFilter
end
]]
end[/lua]

What is really interesting is that the collision still doesn’t register. How is this possible - the physics body is there, there is clearly no filter, and yet still no collision… [import]uid: 59735 topic_id: 33195 reply_id: 131881[/import]

This is odd. Given how Peach and Brandon pointed out some of the common mistakes with collisions, my guess is that it’s your code, or the code generated by the 3rd-party tools. If you can, try to build this scenario with just the two basic objects in “raw Corona” and see if you get the same behavior.

Brent [import]uid: 9747 topic_id: 33195 reply_id: 131891[/import]

Check the lua file physicsEditor creates as that also uses filters.

Dave [import]uid: 117617 topic_id: 33195 reply_id: 131907[/import]

Are the objects in the same group if not is one group not aligned with the other [import]uid: 7911 topic_id: 33195 reply_id: 131917[/import]

Great catch @jstrahan, that’s yet another of the frequent issues with collisions… I should have remembered that one.

@BoltVisual, what he means is, did you “shift” the display group (X/Y) that contains the plant to a different position than the group(s) that contain the character and the building? If so, you’ll see the body shape of the plant traced in the hybrid physics view, but it will not be the correct representation of where the collision will take place. For collisions to function properly, ALL display groups that contain colliding or potentially-colliding bodies must share the same “coordinate space”.

Brent
[import]uid: 9747 topic_id: 33195 reply_id: 131956[/import]

It could be a filter situation. Also, if a physics body has “.isSensor = true” then the collision will register but the objects will pass thru each other. That sounds a little bit like what you’re describing.

Hope this helps. [import]uid: 136211 topic_id: 33195 reply_id: 131861[/import]

Thanks, and It is not a sensor. Do you know if I could remove the filter? [import]uid: 59735 topic_id: 33195 reply_id: 131868[/import]

This is definitely the problem! Thank you! I would have never guessed. I move the group with the plant box and so the collision point for plant never actually moved…However, there really isn’t anything I can do about this because I am using multiple maps which Lime really doesn’t support, so I have to put them into a new group to manipulate them all.

So, my goal is to play a sprite of some leaves when the player collides with the bush.

For now, I think I will request the coordinates of that tile then put a little transparent rectangle to capture the collision then display the leaves sprite.

Anyone have a better workaround? [import]uid: 59735 topic_id: 33195 reply_id: 131970[/import]

You mentioned using Lime, which I’ve never really gotten in to. Not sure how physics bodies are set-up using Lime but I create mine (with filters) using this method:

https://developer.coronalabs.com/forum/2010/10/25/collision-filters-helper-chart

If Lime does apply an unwanted filter, I’m not 100% how to remove it after the object’s already been created. I wonder if something like “body.filter = nil” would work. [import]uid: 136211 topic_id: 33195 reply_id: 131873[/import]

You could try this
http://docs.coronalabs.com/api/type/DisplayObject/contentToLocal.html
Don’t know if it works with physics, never tried it with physics. [import]uid: 7911 topic_id: 33195 reply_id: 131971[/import]

So I was curious and researched a little more myself. It looks as though you aren’t able to change a filter once the object’s body has been created. They recommend removing the body and making another. I saw this here:

http://developer.coronalabs.com/forum/2010/11/08/changing-collision-filters-after-physics-object-created

Granted, the post is a tad old. But just wanted to point it out.

Good luck! [import]uid: 136211 topic_id: 33195 reply_id: 131875[/import]

Are you using more than 8 points in a custom shape? The bodies have lines running through them and I’m wondering if your setup is a little off. Any code for assigning bodies? (Or are they just multiple bodies stacked on top of each other?)

Peach :slight_smile: [import]uid: 52491 topic_id: 33195 reply_id: 131878[/import]

Actually, the bodies where created using physicsEditor, and that was just a poor autotrace.

Interesting, I searched through the Lime module code and found this function which I commented out.
[lua]function addCollisionFilterToBody(item)
–[[
local _item = item

local categoryBits = _item:getPropertyValue(“categoryBits”)
local maskBits = _item:getPropertyValue(“maskBits”)
local groupIndex = _item:getPropertyValue(“groupIndex”)

if(categoryBits or maskBits or groupIndex) then

local collisionFilter = {}

collisionFilter.categoryBits = categoryBits
collisionFilter.maskBits = maskBits
collisionFilter.groupIndex = groupIndex

_item.filter = collisionFilter
end
]]
end[/lua]

What is really interesting is that the collision still doesn’t register. How is this possible - the physics body is there, there is clearly no filter, and yet still no collision… [import]uid: 59735 topic_id: 33195 reply_id: 131881[/import]

This is odd. Given how Peach and Brandon pointed out some of the common mistakes with collisions, my guess is that it’s your code, or the code generated by the 3rd-party tools. If you can, try to build this scenario with just the two basic objects in “raw Corona” and see if you get the same behavior.

Brent [import]uid: 9747 topic_id: 33195 reply_id: 131891[/import]