[SOLVED] convex and concave BOX2d 2.2.0

hi i have problem when i try create convex or concave polygon on box2d 2.2.0

can anyone tell me how to make simple convex or concave polygon box2d 2.2.0 ?
like triangle for convex, and simple shape concave polygon? 😀

sorry for my bad English. 😢
You didn't say what the problem is...

Concave polygons are not supported, so you will need to use two convex polygons to get the same effect. The samples contain many cases where a polygon is created. Check out the HelloWorld example.
Hi,
thanks before for the answer,

the problem is, i just want to create simple triangle shape.
and i don't know how... 😢

i write like this,

var my_body:b2BodyDef= new b2BodyDef();
my_body.position.Set(20/worldScale, 20/worldScale);
my_body.allowSleep = false;
my_body.type = b2Body.b2_staticBody;

var my_box:b2PolygonShape = new b2PolygonShape();
my_box.vertices[0].Set(0, -1);
my_box.vertices[1].Set(1,1);
my_box.vertices[2].Set(-1,1);
my_box.Set(my_box.vertices, 3);

var my_fixture:b2FixtureDef = new b2FixtureDef();
my_fixture.density=1.5;
my_fixture.friction=0.8;
my_fixture.restitution=0.3;
my_fixture.shape=my_box;

boxSphere = world.CreateBody(my_body);
boxSphere.CreateFixture(my_fixture);

but still Error and said :
1119: Access of possibly undefined property vertices through a reference with static type Box2D.Collision.Shapes:b2PolygonShape.

can you give me some simple sample how to make triangle in box2d 2.2.0? 🙂
This is because you're trying to access my_box's nonexistent "vertices" property. What you want is to create an array or vector of b2Vec2 objects, then use my_box.SetAsArray to set the vertices (or my_box.SetAsVector if you're using a Vector instead of an Array).
Hi,
thanks for solution,

but i still confuse how to write SetAsArray or SetAsVector in my_box ?
i had write like this :

my_box.SetAsArray(0, 3);
or
my_box[0]SetAsArray (0, 3);

but still Error.
can you give me full code simple sample how to create triangle?

Really thanks to you.
Using the code from your first post:
Code:
var my_body:b2BodyDef= new b2BodyDef();
my_body.position.Set(20/worldScale, 20/worldScale);
my_body.allowSleep = false;
my_body.type = b2Body.b2_staticBody;

var my_vertices:Array = new Array();
my_vertices.push(new b2Vec2(0,-1));
my_vertices.push(new b2Vec2(1,1));
my_vertices.push(new b2Vec2(-1,1));

var my_box:b2PolygonShape = new b2PolygonShape();
my_box.SetAsArray(my_vertices, 3);
         
var my_fixture:b2FixtureDef = new b2FixtureDef();
my_fixture.density=1.5;
my_fixture.friction=0.8;
my_fixture.restitution=0.3;
my_fixture.shape=my_box;
         
boxSphere = world.CreateBody(my_body);
boxSphere.CreateFixture(my_fixture);


If an error says b2Vec2 is unknown or something, you'll have to import Box2D.Common.Math.b2Vec2.
Hi jayther,
Really thanks, the code is really work 😀

Thanks again for you,,, 😉

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