Skip to content

Commit f22b913

Browse files
committed
🐛 Fix gravitational source on disabled components
1 parent 85d75b4 commit f22b913

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/physics/rigidBody.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RigidBody final : public Component {
3838
}
3939

4040
void update(float deltaTime) override {
41-
if (!transform) {
41+
if (!transform || !isEnabled()) {
4242
return;
4343
}
4444

@@ -87,14 +87,18 @@ class RigidBody final : public Component {
8787

8888

8989
void addGravitationalSource(const RigidBody &source) {
90+
if (!isEnabled() || !source.isEnabled()) {
91+
return;
92+
}
93+
9094
static const float G = 6.67430e-11; // Gravitational constant
9195

9296
glm::vec4 r = source.getPos() - getPos();
9397
float distance = math::norm(r);
9498
glm::vec4 direction = math::normalize(r);
9599

96100
glm::vec4 force = G * (mass * source.mass) / (distance * distance) * direction;
97-
forceAccumulator += force;
101+
applyForce(force);
98102
}
99103

100104
private:

0 commit comments

Comments
 (0)