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?