I'm currently working on integrating Bullet SDK into my game engine. Currently I'm trying to apply a force to my objects using a mouse click. So far I've failed. Here is the code that is called when an object is clicked on:
void PhysicsComponent::ApplyForce(glm::vec3& hitPoint, glm::vec3& direction, float amount)
{
if (!m_body)
return;
m_body->activate(true);
btVector3 force = btVector3(0, 1, 0) * amount;
m_body->applyImpulse(force, centerOfMass);
}
If I use the same idea in my update() function, it works fine. Why is this?
Solved it.
Issue had nothing to do with Bullet. I was storing my Physics Components in a vector as references and attaching &(m_physicsComponents.back()) to my Objects. Evey time the vector resized 1 object would break. I just hadn't noticed the issue until now, since the broken object happened to be what my test object was sitting on. Changed my vector to store pointers and everything works.