Unable to detect collision for transitioning bodies

Hi all,

I previously posted about not being able to detect collision for rotating objects which ended up being because they have too many vertices : 

https://forums.coronalabs.com/topic/58321-unable-to-detect-collision-for-rotating-objects/

What I’m trying to do now is to create a rectangle.

movingPolygons = { { vertices={200,600,240,600,240,680,200,680}, xStart=218,yStart=800,xEnd=400,yEnd=800 } }



for i=1,#bank.levels[levelNumber].movingPolygons do local vertices = bank.levels[levelNumber].movingPolygons[i].vertices local p4 = createLevelPolygon(parent,vertices,3,1.0,globalYOffset,true) p4.xStart = bank.levels[levelNumber].movingPolygons[i].xStart p4.yStart = bank.levels[levelNumber].movingPolygons[i].yStart + globalYOffset p4.xEnd = bank.levels[levelNumber].movingPolygons[i].xEnd p4.yEnd = bank.levels[levelNumber].movingPolygons[i].yEnd + globalYOffset alternateTransition(p4) end



local function createLevelPolygon(parent,vertices,strokeWidth,strokeAlpha,globalYOffset,isPhysics) local polygon = display.newPolygon( 0,0, vertices ) polygon:setFillColor(0) polygon.strokeWidth = strokeWidth polygon:setStrokeColor( colors.levelColor[1],colors.levelColor[2],colors.levelColor[3],stro keAlpha ) parent:insert(polygon) offsetObject(polygon,vertices) polygon.y = polygon.y + globalYOffset if isPhysics then physics.addBody( polygon , "static",{density=3.0,isSensor=true}) end table.insert(items, polygon) return polygon end

Move it from left to right to left…

local function alternateTransition( polygon ) transition.to(polygon,{time=4000,x=polygon.xEnd,y=polygon.yEnd, onComplete = function() transition.to(polygon,{time=4000,x=polygon.xStart,y=polygon.yStart, onComplete=function() alternateTransition(polygon) end}) end}) end

I have another circle that I control

physics.addBody(circleWheel.circlePoint,"dynamic",{radius=3,isSensor=true})

I setup collision detection

local function onGlobalCollision( event )     print("globalCollision") end Runtime:addEventListener( "collision", onGlobalCollision )

When I move into the circle into the polygon using transition.to, a collision is detected.

When the polygon transitions into the circle however, the collision is not detected.

Here is a video :

https://www.youtube.com/watch?v=zhE6Sht7ku4&feature=youtu.be

Other notes :

Am using the perspective camera library

The bounds of the bodies look ok using physics.setDrawMode( “hybrid” )

Any ideas ? Thanks in advance,

Hi @wuhu.apps,

As a quick test, can you simply test these objects against each other without any usage of the “perspective” library? Just place them on the stage (even a new test project if necessary) and see if you get collision detection.

Thanks,

Brent

Hi Brent,

Thanks for the suggestion.

I started a new project as you suggested to break it down and discovered that my level objects that are moving have to have the “dynamic” parameter when adding physics bodies. The level objects that don’t move have to have the “static” parameter.

I had previously tried this but my test level had the moving object knocking into the static objects constantly giving weird results  :unsure: .

Thanks and problem resolved for now

Hi @wuhu.apps,

In any collision, at least one body must be “dynamic” type (default unless you specify another type). You’ll never get a collision between static+static, kinematic+kinematic, or static+kinematic.

Brent

P.S. - your game looks nice so far, keep up the progress!

Hi @wuhu.apps,

As a quick test, can you simply test these objects against each other without any usage of the “perspective” library? Just place them on the stage (even a new test project if necessary) and see if you get collision detection.

Thanks,

Brent

Hi Brent,

Thanks for the suggestion.

I started a new project as you suggested to break it down and discovered that my level objects that are moving have to have the “dynamic” parameter when adding physics bodies. The level objects that don’t move have to have the “static” parameter.

I had previously tried this but my test level had the moving object knocking into the static objects constantly giving weird results  :unsure: .

Thanks and problem resolved for now

Hi @wuhu.apps,

In any collision, at least one body must be “dynamic” type (default unless you specify another type). You’ll never get a collision between static+static, kinematic+kinematic, or static+kinematic.

Brent

P.S. - your game looks nice so far, keep up the progress!