How to simulate a heightfield terrain

this one should work fine, i will try it:
Code:
function makeLine(b2Body body, p1:Point, p2:Point)
{
     //the body is just a new body you created
     var polygonDef = new PolygonDef();
     var xOffset:Number = p2.x - p1.x;
     var yOffset:Number = p2.y - p1.y;
     var length = Math.sqrt(xOffset * xOffset + yOffset * yOffset) * 0.5;
     var angle = Math.atan2(yOffset, xOffset);
     polygonDef.SetAsBox(length, 1);
     body.CreateShape(polygonDef);
     body.SetXForm(b2Vec2(p1.x - cos(angle) * length , p1.y - sin(angle) * length), angle);
}
I guess BorisTheBrave just provided the answer in his first reply.
Spawn a shape for every section of your terrain-line.

Like so:
Question to the trapezoids: You could also do triangles and use one side for the terrain segment, right? Does something like this save a lot of processing power or is there some optimization in using boxes?
Another performance question:
Is it better to create one huge body containing all terrain shape definitions or is it better to create a body for every single trapezoid shape?
i think one hiuge terrain
There always a default ground body in box2d. Use that one for all you static ground shapes.

Use trapezoids. There will be less of them than if you used triangles.

-nick
all static shapes in one body??
how many shapes can i add to one body?

currently i have one body for every line-shape - and there are
a lot 🙂 i think i have to make some performance tests...

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