Hello all.
I implemented a body falling diagonally from top left to bottom right. I did this by setting 2 diagonal parallel edges, and my body in between.
Sow when the simulation starts, I can se the body falling along/between these edges.
The problem is that when I drag the body, I can drag it outside these edges when stop dragging, the body kinda goes to where is supposed to be (between the edges, and start falling again), and if I drag somewhere where more than half of the body is outside the device edges, the body simply falls in that position and disappear.
This is the code Im using.
CGSize winSize = [[CCDirector sharedDirector] winSize];
b2Vec2 gravity = b2Vec2(0.0,-10.0);
bool doSleep = true;
_world = new b2World(gravity,doSleep);
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
_groundBody = _world->CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
//left diagonal edge
groundBox.SetAsEdge(b2Vec2(395/PTM_RATIO,0), b2Vec2(80/PTM_RATIO,winSize.height/PTM_RATIO));
_groundBody->CreateFixture(&groundBox,0);
//Right right diagonal edge
groundBox.SetAsEdge(b2Vec2((winSize.width+5)/PTM_RATIO,285/PTM_RATIO), b2Vec2(545/PTM_RATIO,winSize.height/PTM_RATIO));
_groundBody->CreateFixture(&groundBox,0);
//Right edge
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(0,winSize.height/PTM_RATIO));
_groundBody->CreateFixture(&groundBox,0);
//top top edge
groundBox.SetAsEdge(b2Vec2(0,935/PTM_RATIO), b2Vec2(540/PTM_RATIO,1100/PTM_RATIO));
_groundBody->CreateFixture(&groundBox,0);
//Bottom -edge
groundBox.SetAsEdge(b2Vec2(50/PTM_RATIO,0), b2Vec2(990/PTM_RATIO,290/PTM_RATIO));
b2Fixture * bt = _groundBody->CreateFixture(&groundBox,0);
bt->SetRestitution(0.3);
//Setting the taleBox
b2PolygonShape shape;
shape.SetAsBox((tale.contentSize.width/2)/PTM_RATIO, (tale.contentSize.height/2)/PTM_RATIO);
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 0.1;
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(tale.position.x/PTM_RATIO,tale.position.y/PTM_RATIO);
bd.userData = tale;
bd.fixedRotation = true;
bd.angle = -1 * CC_DEGREES_TO_RADIANS(tale.rotation);
b2Body* body = _world->CreateBody(&bd);
body->CreateFixture(&fd);
Any ideas?
I saw with a prismatic joint I can restrict this movement, but along a axis, X,Y, relative to the world, but I dunno how can I tell the engine to do it along a diagonal edge.
Thanks
Gustavo