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,