Collision, collision, no collision?

Im pretty sure this isnt a standard problem for people to come across but it wont stop and I cant see any bug to do with it. I created a class to make polygons on the go and rectangles and such but when I make a polygon the player (a physical body) will collide with it a couple times maybe more, and then stop colliding with it all together, but the mesh will still be there. This means that the player is walking through the world which is made from a polygon from the following function:

meshes = {}
imesh = 0
function CreateBox:createpoly(vert,x,y,type)
    imesh=imesh+1
    newvert = {}
    self.body = physics.body(POLYGON,unpack(vert))
    self.body.x = x
    self.body.y = y
    self.body.type = type
    self.body.sleepingAllowed = false
    self.m = mesh()
    meshes[imesh] = self.m
    for i = 1,#triangulate(vert) do
        newvert[i] = triangulate(vert)[i]
        newvert[i] = newvert[i] + vec2(x+10,y+10)
    end
    self.m.vertices = newvert
    self.m:setColors(255,255,255)
    return {self.body,self.m}
end
function CreateBox:draw()
    -- Codea does not automatically call this method
    for i = 1,#meshes do
        meshes[i]:draw()
    end
end



CreateBox():createpoly(Levels[1],WIDTH-200,25,STATIC)

Has anyone else had this problem? I dont think it occurs if im not using a for loop to make the different bodies, any input is great thanks.

Do you hold a reference to all physics objects used, otherwise the garbage collector will remove it. I ran into that bug a while ago. :slight_smile:

ahhh no That will probably be it, because the createbox:create function returns a body so i need to put them all in a table or something, thanks!

Glad it helped. I’ve wasted so much time on that issue :slight_smile:

I have a problem like that.
A bouncing ball ignores the walls at second collision but the floor stays fine.

@Kire - make sure you put the wall bodies into global variables

physics.body(EDGE, ....   --not in any variable, will be deleted
local b=physics.body(EDGE, ....   --will be deleted
b=physics.body(EDGE, ....   --will NOT be deleted

@Ignatz
This is what I’m using.

wall1= physics.body(EDGE, vec2(0, HEIGHT), vec2(0, 0))

@Kire Here’s a simple example of a bouncing ball. There are no problems with the wall. How does this compare to the code you’re having trouble with.

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    w1=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
    w2=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
    w3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
    
    b=physics.body(CIRCLE,20)
    b.x=WIDTH/2
    b.y=HEIGHT/2
    b.restitution=1
    b.friction=0
    b.linearVelocity=vec2(400,20)
end

function draw()
    background(40, 40, 50)
    fill(255)
    ellipse(b.x,b.y,40)
end