[Solved] Issues applying impulse on mouse click

inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

[Solved] Issues applying impulse on mouse click

Post by inzombiak »

Hi, I'm working on implementing a game using Bullet SDK. Right now I'm trying to apply impulse to my game objects when theyre clicked on.
When I run the following code in my "ApplyForce" funciton, which is called when an object is clicked, nothing happens

Code: Select all

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);

}
But if I use the same idea in my "Update" function, which is called every step, it works. By same code I mean applying a set impulse to the center of my object.

What could be causing this?
Last edited by inzombiak on Tue Jan 19, 2016 11:41 am, edited 1 time in total.
inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

Re: Issues applying impulse on mouse click

Post by inzombiak »

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.