The problem is on video, collision aren't working properly. Is there any solution or can i show the collision edges on window.
the video: https://streamable.com/w96uff
CreateGround Function
b2BodyDef BodyDef;
BodyDef.position = b2Vec2(X / 30.f, Y / 30.f);
BodyDef.type = b2_staticBody;
b2Body* Body = World.CreateBody(&BodyDef);
b2PolygonShape Shape;
Shape.SetAsBox(400 / 30, 50 / 30); // Creates a box shape. Divide your desired width and height by 2.
b2FixtureDef FixtureDef;
FixtureDef.density = 1.f; // Sets the density of the body
FixtureDef.shape = &Shape; // Sets the shape
Body->CreateFixture(&FixtureDef); // Apply the fixture definition
**CreateBox() Function**
b2BodyDef BodyDef;
BodyDef.position = b2Vec2(MouseX / 30, MouseY / 30);
BodyDef.type = b2_dynamicBody;
b2Body* Body = World.CreateBody(&BodyDef);
b2PolygonShape Shape;
Shape.SetAsBox(16.0f / 30, 16.0f / 30);
b2FixtureDef FixtureDef;
FixtureDef.density = 1.0f;
FixtureDef.friction = 0.7f;
FixtureDef.shape = &Shape;
Body->CreateFixture(&FixtureDef);
While window is open loop:
for (b2Body* BodyIterator = World.GetBodyList(); BodyIterator != 0; BodyIterator = BodyIterator->GetNext())
{
if (BodyIterator->GetType() == b2_dynamicBody)
{
sf::Sprite Sprite;
Sprite.setTexture(WoodTexture);
//Sprite.setOrigin(32.f, 32.f);
Sprite.setPosition(30 * BodyIterator->GetPosition().x, 30 * BodyIterator->GetPosition().y);
Sprite.setRotation(BodyIterator->GetAngle() * 180 / b2_pi);
Sprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
gameWindow.draw(Sprite);
}
else
{
MetalGround.setOrigin(400.f, 15.f);
MetalGround.setPosition(BodyIterator->GetPosition().x * 30, BodyIterator->GetPosition().y * 30);
MetalGround.setRotation(180 / b2_pi * BodyIterator->GetAngle());
gameWindow.draw(MetalGround);
}
}
EDIT: Okey okey i fixed the rolling thing but one more thing to done:
https://streamable.com/dgpawo as you can see the boxes doesn't stay still, they are sliding too much.