EdgeShapes (aka Thin Line Segments)

YagerX wrote:
hm i'm having trouble using the chains... It keeps throwing "Shape type not found or cannot be added to Dynamic Bodies."
but uh i'm adding the chain to a new body so shouldn't it be static?


I don't think you can just add the chain to a normal body, if you use the code that shaktool posted on page 3, you can use normal bodies, but adding a chain to them requires a slightly different treatment. (not body.CreateShape) I will repost:
Code:
var bd:b2BodyDef = new b2BodyDef();
body = phys.CreateBody(bd);
           
var chain:b2StaticEdgeChainDef = new b2StaticEdgeChainDef();
chain.vertexCount = points.length;
chain.isALoop = false;         
for each(var point:b2Vec2 in points){
   chain.vertices.push(new b2Vec2(point.x, point.y));
}
edgeChain = new b2StaticEdgeChain(chain, phys, body);

Pay special attention to the last line.
ah thanks.
Didn't know i had to do that
Sorry i'm asking alot of you right now, but is it possible to assign different friction values for each edge?
YagerX wrote:
ah thanks.
Didn't know i had to do that
Sorry i'm asking alot of you right now, but is it possible to assign different friction values for each edge?

No problem... I think in principle, each segment is a b2Shape, so it has a friction value. It's not accessable though, because you use a b2StaticEdgeChainDef to create them, so the friction for each staticEdge in the chain is set to the same value. You could modify it so you can set the friction for each edge separately, but I don't know how.. So I think it's better to just make a new chain for each section you want to have a different friction value.
Hm yea... I found a way around the problem (decided to use a diff method for what i was doing)
But it would be good if we could edit the friction on specific edges...
shaktool wrote:
I am working on the C++ port. It will not have any of BorisTheBrave's code in it. It will probably allow the line segments to be added to dynamic bodies. The API will be closer to the standard Box2D api.


How is that coming along? 🙂
The beta C++ port is 85% - 90% done. Hopefully I'll have time to finish it when I get home tonight.

Oh yeah, and I have been unable to reproduce the "sinking" behavior you found earlier. Would it be possible for you to set that up in a testbed example that I could compile?
The C++ port is at:
viewtopic.php?f=3&t=1577
shaktool wrote:
Would it be possible for you to set that up in a testbed example that I could compile?

Took me a while to reproduce the behavior outside of it's specific situation, but it's reliably occurring now.

Here is the package you posted earlier, with an extra TestBed Class added to it..
How is the performance of a map using thin line segments opposed to tons of boxes? Is it comparable?
Ygryggil wrote:
How is the performance of a map using thin line segments opposed to tons of boxes? Is it comparable?


I found that line segments is quicker. (I used an optimized set of polygons to create terrain, but I found that line segments make for a faster simulation).

Original thread: https://box2d.org/forum/viewtopic.php?t=1437