Skip to main content
More specific title. Corrected grammar and proofread. Reformatted example code to make it easier to read.
Source Link
Anko
  • 13.4k
  • 10
  • 55
  • 82

How to use In Box2D stored bullets, how can I SetTransform of a body without getting an IsLocked assertion error?

Yup i know there isI've created a "Assertion failed: (IsLocked() == false" problem caused by world->step(...) in update function. And I have to had my bullet body and stored after initialization.a reference to it in herobody:

bDef.type = b2_dynamicBody;
bDef.position.Set(herobody->GetPosition().x, herobody->GetPosition().y);
b = world->CreateBody(&bDef);
b2FixtureDef fixturebDef;
b2CircleShape circlebShape;
circlebShape.m_radius = 0.05;
fixturebDef.shape = &circlebShape;
b->CreateFixture(&fixturebDef);

but i dont know howI'm trying to change the current position of the bullet connected with herobody. I tried to use setTransform b2bodySetTransform but it make the same asseration problemI get an error :(Assertion failed: (IsLocked() == false) during world->step in my update method.

/// This doesn't work. Causes the above assertion.
/*
b->SetTransform(
  b2Vec2(
    herobody->GetPosition().x,
    herobody->GetPosition().y
  ),
  0 
); 
*/

// DOESThis NOTworks, WORK;/but doesn't set position directly.
b->ApplyLinearImpulse(b2Vec2(5, 0), b->GetWorldCenter(),true);

Can anyone know how to fix it or how to write correct function forHow do I do this correctly?

How to use Box2D stored bullets?

Yup i know there is a "Assertion failed: (IsLocked() == false" problem caused by world->step(...) in update function. And I have to had my bullet stored after initialization.

bDef.type = b2_dynamicBody;
bDef.position.Set(herobody->GetPosition().x, herobody->GetPosition().y);
b = world->CreateBody(&bDef);
b2FixtureDef fixturebDef;
b2CircleShape circlebShape;
circlebShape.m_radius = 0.05;
fixturebDef.shape = &circlebShape;
b->CreateFixture(&fixturebDef);

but i dont know how to change the current position of the bullet connected with herobody. I tried to use setTransform b2body but it make the same asseration problem :(

/// b->SetTransform(b2Vec2(herobody->GetPosition().x, herobody->GetPosition().y), 0); // DOES NOT WORK;/
b->ApplyLinearImpulse(b2Vec2(5, 0), b->GetWorldCenter(),true);

Can anyone know how to fix it or how to write correct function for this?

In Box2D, how can I SetTransform of a body without getting an IsLocked assertion error?

I've created a bullet body and stored a reference to it in herobody:

bDef.type = b2_dynamicBody;
bDef.position.Set(herobody->GetPosition().x, herobody->GetPosition().y);
b = world->CreateBody(&bDef);
b2FixtureDef fixturebDef;
b2CircleShape circlebShape;
circlebShape.m_radius = 0.05;
fixturebDef.shape = &circlebShape;
b->CreateFixture(&fixturebDef);

I'm trying to change the current position of the bullet. I tried to use SetTransform but I get an error Assertion failed: (IsLocked() == false) during world->step in my update method.

// This doesn't work. Causes the above assertion.
/*
b->SetTransform(
  b2Vec2(
    herobody->GetPosition().x,
    herobody->GetPosition().y
  ),
  0 
);
*/

// This works, but doesn't set position directly.
b->ApplyLinearImpulse(b2Vec2(5, 0), b->GetWorldCenter(),true);

How do I do this correctly?

Source Link
dex3
  • 23
  • 4

How to use Box2D stored bullets?

Yup i know there is a "Assertion failed: (IsLocked() == false" problem caused by world->step(...) in update function. And I have to had my bullet stored after initialization.

bDef.type = b2_dynamicBody;
bDef.position.Set(herobody->GetPosition().x, herobody->GetPosition().y);
b = world->CreateBody(&bDef);
b2FixtureDef fixturebDef;
b2CircleShape circlebShape;
circlebShape.m_radius = 0.05;
fixturebDef.shape = &circlebShape;
b->CreateFixture(&fixturebDef);

but i dont know how to change the current position of the bullet connected with herobody. I tried to use setTransform b2body but it make the same asseration problem :(

/// b->SetTransform(b2Vec2(herobody->GetPosition().x, herobody->GetPosition().y), 0); // DOES NOT WORK;/
b->ApplyLinearImpulse(b2Vec2(5, 0), b->GetWorldCenter(),true);

Can anyone know how to fix it or how to write correct function for this?