Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
fix torque
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Jul 26, 2023
1 parent 3567cb3 commit 7331b9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [v0.4](https://github.com/godot-box2d/godot-box2d/releases/tag/v0.4)

- Fix torque (almost, there is still a little difference in test, but numbers are much more closer now)
- Fix concave polygon
- Add support for conveyer belt
- Add build for web but not enabled yet (bug in godot-cpp)

## [v0.3](https://github.com/godot-box2d/godot-box2d/releases/tag/v0.3)

- Fix mac binary signing
Expand Down
8 changes: 4 additions & 4 deletions src/bodies/box2d_collision_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void Box2DCollisionObject::apply_impulse(const Vector2 &impulse, const Vector2 &
}
void Box2DCollisionObject::apply_torque_impulse(double impulse) {
if (body && body->GetType() == b2BodyType::b2_dynamicBody) {
body->ApplyTorque((1.0f / mass_data.I) * impulse, true);
body->ApplyAngularImpulse(body->GetInertia() * godot_to_box2d(impulse), true);
}
}
void Box2DCollisionObject::apply_central_force(const Vector2 &force) {
Expand All @@ -370,7 +370,7 @@ void Box2DCollisionObject::apply_force(const Vector2 &force, const Vector2 &posi
}
void Box2DCollisionObject::apply_torque(double torque) {
if (body && body->GetType() == b2BodyType::b2_dynamicBody) {
body->ApplyTorque(body->GetMass() * godot_to_box2d(torque), true);
body->ApplyTorque(body->GetInertia() * godot_to_box2d(torque), true);
}
}

Expand Down Expand Up @@ -805,7 +805,6 @@ void Box2DCollisionObject::_update_shapes() {
float old_mass = mass_data.mass;
// update inertia and center of mass
mass_data = body->GetMassData();
body->GetInertia();
// revert mass
mass_data.mass = old_mass;
body->SetMassData(&mass_data);
Expand All @@ -824,7 +823,8 @@ void Box2DCollisionObject::before_step() {
}
if (constant_forces.constant_torque != 0) {
// constant torque
body->ApplyTorque(body->GetMass() * constant_forces.constant_torque, true);

body->ApplyTorque(body->GetInertia() * constant_forces.constant_torque, true);
}
}
}
Expand Down

0 comments on commit 7331b9a

Please sign in to comment.