I have this block based game engine I’m making, and each of the block is a POLYGON collision body. the walls/floors are STATIC bodies made up of blocks. Heres a video of the problem: http://snk.to/f-ct321ey8
I hope you see, in the video, the blocks collision seems to be on a concave surface when landing from above, But slides perfectly. Also, the blocks are also jiggling a little bit I noticed.
the code snippets for the physics:
– … Only parts of the code
– This is the code for creating all the collision based on the table “self.table”
– Because the table stores the map coordinates, not the actual coordinates of the screen, the I need to multiply them by the blocks pixel width
for i, v in ipairs(self.collision) do
for i2, block in ipairs(v) do
if block ~= "" then
local body = physics.body(POLYGON, vec2(-WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2), vec2(-WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2))
body.type = STATIC
local collision = PhysicsEntity("", block.x, block.y, WorldSettings.BLOCK_SIZE.x, WorldSettings.BLOCK_SIZE.y, body)
table.insert(self.collisionBody, collision)
end
end
end
– The code for making the test objects
local testBody01 = physics.body(POLYGON, vec2(-WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2), vec2(-WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2))
testBody01.sleepingAllowed = false
testBody01.mass = 1
testBody01.restitution = 0.5
self.testBox01 = PhysicsEntity("Platformer Art:Block Brick",2 ,6 , WorldSettings.BLOCK_SIZE.x, WorldSettings.BLOCK_SIZE.y, testBody01)
local testBody02 = physics.body(POLYGON, vec2(-WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2), vec2(-WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,WorldSettings.BLOCK_SIZE.y/2), vec2(WorldSettings.BLOCK_SIZE.x/2,-WorldSettings.BLOCK_SIZE.y/2))
testBody02.sleepingAllowed = false
testBody02.mass = 1
testBody02.restitution = 0.5
self.testBox02 = PhysicsEntity("Platformer Art:Block Brick",3 ,6 , WorldSettings.BLOCK_SIZE.x, WorldSettings.BLOCK_SIZE.y, testBody02)