Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Collision filter not working for chain bodies
Started by sporkfin Nov 23 2018 01:24 PM

7 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 425 posts
  • Corona SDK

I'm currently using the Corona Collision Filters plug-in and I'm unable to get collision filters to work with chain bodies.  Before I go through the trouble of remaking my filters the old way (with category bits ) to further test this problem, I'm wondering if this is an oversight in the plugin or a Boxed 2D limitation.  Anyone know?

 

I have a filter called "null" which sets to not collide with anything.  When I apply this to the chain body's filter, nothing happens.

 

        physics.addBody( terra.cent, "static", -- terra.cent is the center point of the object
            {
                chain=vertices2,
                connectFirstAndLastChainVertex = true,
                filter=mt.cf.null  -- mt.cf is the pathway to the collision filters - null means no collisions
            } )
 
    ------------------------------



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 425 posts
  • Corona SDK

OK, I also noticed that I can't add eventListeners to the chain body - or at least they don't trigger collision reports even though they are active in the physics environment

 

local function shoutOut( e )
    local name = e.other.name or " who knows?"
    print( "The ground is touching", name )
end
 
terra.cent:addEventListener( "collision", shoutOut )
 
I use chain bodies to make landscapes which, until now, have been simple barriers but now I'm trying to add some more complex behaviors and I've encountered the two issues above with chain bodies.  Any insights are appreciated, thanks everyone.


[TOPIC: post.html]
#3

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

The collision filters and collision events work fine. I have one game that is completely built around them and I haven't run into any issues. I personally always use the old school collision filters as described in the docs. You probably just have an oversight somewhere in your code or in the plugin.

Try out the following code. It should work as you described. I copied a simple collision event from the docs and added two settings for filterObject that you can try out.

 

local physics = require("physics")
physics.setDrawMode( "hybrid" )
physics.start()

-- uncomment one of these 
-- local filterObject = { categoryBits=1, maskBits=1 } -- maskBits=1 results in no collision with filterGround
local filterObject = { categoryBits=1, maskBits=3 } -- maskBits=3 results in collision with filterGround

local filterGround = { categoryBits=2, maskBits=1 }

local function onLocalCollision( self, event )
	if ( event.phase == "began" ) then
		print( self.myName .. ": collision began with " .. event.other.myName )
	end
end

local ground = display.newRect( 240, 240, 320, 40 )
physics.addBody( ground, "static", {filter=filterGround} )
ground.myName = "ground"
ground.collision = onLocalCollision
ground:addEventListener( "collision" )

local rect = display.newRect( 240, 40, 80, 20 )
physics.addBody( rect, "dynamic",
	{
		chain={ -40,-10,40,-10,40,10,-40,10 },
		connectFirstAndLastChainVertex = true,
		filter=filterObject
	}
)
rect.myName = "rect"
rect.collision = onLocalCollision
rect:addEventListener( "collision" )

I've created an excel file for easy collision filter setup. If you need it, I can upload it here for you tomorrow.

Update: I tried giving both objects chain physics bodies and it seems that if both objects are made out of chains, then they don't collide regardless of the collision filter values.



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 425 posts
  • Corona SDK

@XeduR, thanks!

 

OK, that explains chain bodies vs chain bodies.  I'll pull up my old manual filters and see if I can get them to work with chain vs. standard bodies.  I'll PM you about the excel sheet.  I have a system I set up but I'm always happy to try one that might be faster.  Thanks again!



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

As the forums don't allow the uploading of excel files, if anyone else needs the file, just let me know. The file does the calculations and filter setups automatically. All that's left is to rename any filter and add any character to a "category" or "collides with" cell and the file manages the rest.



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

You can zip up the excel file to attach it.

 

Click 'more reply options' below to upload it.


  • XeduR @Spyric likes this

[TOPIC: post.html]
#7

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

Brilliant as usual, Ed! :D

Here it is, if someone needs it.

Attached Files



[TOPIC: post.html]
#8

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 425 posts
  • Corona SDK

@XeduR  Thanks for the collision filter excel file.  It works great!  Unfortunately, I'm still having the problem but I'm fairly certain it is indeed a problem with my code and not a system glitch or oversight.  Some of my chain bodies have close to 1,000 vertices and I fear there is an overlap somewhere that is causing the errors.  I've checked them extensively mathematically and in hybrid mode but I just can't come up with any culprits.

 

I'll keep trying and thanks again for your input.




[topic_controls]
[/topic_controls]