I have a chain that boxes in the game field. But sometimes objects, moving fast, can ignore the boundary and pass through it…how can I fix this?
See physics.continuous and “bullet” under physics.body in the reference.
@dave1707 I’ve noticed in Codea 2.0 sometimes this doesn’t make a difference when using a chain body. It only happens when the game is below 35fps and I think it could be fixed by adding in more iterations, I haven’t tried this.
@Luatee I just tried a physics.body(CHAIN,…) and a physics.body(CIRCLE,0), (the smallest I could set the CIRCLE size). I set the linearVelocity of the CIRCLE to a velocity of 120 and the CIRCLE went thru the CHAIN. I then set physics.continuous=true and set the velocity to it max (3840) and the CIRCLE was stopped by the CHAIN each time. So it appears that physics.continuous works. I didn’t bother to set bullet to anything.
I’m operating at 160 velocity on the x, 0 on the y, radius of 1…hit or miss sometimes
@Invad3rZIM Without seeing the code it’s hard to say why it’s not working. In my test, I even set the CIRCLE size to 0 with a speed of 3840 and it was stopped by the CHAIN. I had physics.continuous=true in the setup() function.
@Invad3rZIM Are all of your velocities based on physics movement. If you move physics objects directly, then that causes problems.
@dave1707 yes, circles work flawlessly I know. But try this polygon:
local verts = {vec2(-9,0),vec2(-9,-4),vec2(-5,-6),vec2(0,-6),vec2(5,-6),vec2(9,-5),vec2(10,-3),vec2(10,3),vec2(7,6),vec2(4,5),vec2(2,4),vec2(-2,5),vec2(-6,4)}
And maybe more of a constant force on a jagged chain.
I’ve come to notice box2D has unreliable physics when using some sets of vertices, like a polygon rectangle with chamfered corners (45 degrees 16 pixel chamfer, total of 8 points) will cause bodies to pass through.
@Luatee I tried your verts on a POLYGON with a jagged CHAIN and it stops every time, even at max velocity. Maybe we’re doing thing differently.
@Luatee Here the code I was testing with.
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
verts = {vec2(-9,0),vec2(-9,-4),vec2(-5,-6),
vec2(0,-6),vec2(5,-6),vec2(9,-5),
vec2(10,-3),vec2(10,3),vec2(7,6),
vec2(4,5),vec2(2,4),vec2(-2,5),vec2(-6,4)}
physics.continuous=true -- comment this and the chain wont stop the polygon
end
function setup1()
maxVel=0
if p then
p:destroy()
d:destroy()
end
p=physics.body(POLYGON,unpack(verts))
p.x=0
p.y=421
p.gravityScale=0
tab={}
for z=1,50 do
table.insert(tab,vec2(900+math.random(100),z*20-20))
end
d=physics.body(CHAIN,false,unpack(tab))
end
function draw()
background(40,40,50)
fill(255)
stroke(255)
strokeWidth(2)
if p then
for z=2,#tab do
line(tab[z-1].x,tab[z-1].y,tab[z].x,tab[z].y)
end
i=#verts
p:applyForce(vec2(200,0))
for z=1,#verts do
line(p.x+verts[i].x,p.y+verts[i].y,p.x+verts[z].x,p.y+verts[z].y)
i=z
end
maxVel=math.max(p.linearVelocity.x,maxVel)
text("Velocity "..maxVel,WIDTH/2,HEIGHT-60)
text("Max velocity is 3840",WIDTH/2,HEIGHT-30)
end
text("tap screen to start",WIDTH/2,HEIGHT-90)
end
function touched(t)
if t.state==BEGAN then
setup1()
end
end
@dave1707 we are doing it differently, I’ve got a five second clip of the foot going through and it looks like it’s at where two points meet in the chain body, but I’m going to try a few other things
You can send it.