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

Commit

Permalink
Fix impulse at point (#85)
Browse files Browse the repository at this point in the history
* Update release.yml

* use godot cpp 4.2

* Update release.yml

* Update runner.yml

* Update release.yml

* Update action.yml

* Update release.yml

* update

* Update release.yml

* put version in plugin.cfg

* Update action.yml

* only do release builds

* fix collide function

* fix impulse at point
  • Loading branch information
Ughuuu authored Dec 10, 2023
1 parent 4fca855 commit b33136f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/bodies/box2d_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void Box2DBody2D::apply_central_impulse(const Vector2 &p_impulse) {

void Box2DBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) {
impulse += p_impulse;
torque += (p_position - get_center_of_mass()).cross(p_impulse);
torque += p_position.cross(p_impulse);
if (!get_space()) {
return;
}
Expand All @@ -664,7 +664,8 @@ void Box2DBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_posit

ERR_FAIL_COND(!box2d::is_handle_valid(body_handle));
b2Vec2 impulse = { p_impulse.x, p_impulse.y };
b2Vec2 pos = { p_position.x, p_position.y };
Vector2 point_centered = get_transform().get_origin() + p_position + get_center_of_mass();
b2Vec2 pos = { point_centered.x, point_centered.y };
box2d::body_apply_impulse_at_point(space_handle, body_handle, impulse, pos);
}

Expand Down Expand Up @@ -711,7 +712,7 @@ void Box2DBody2D::apply_force(const Vector2 &p_force, const Vector2 &p_position)
// Note: using last delta assuming constant physics time
real_t last_delta = get_space()->get_last_step();
impulse += p_force * last_delta;
torque += (p_position - get_center_of_mass()).cross(p_force) * last_delta;
torque += p_position.cross(p_force) * last_delta;
if (!get_space()) {
return;
}
Expand All @@ -725,7 +726,8 @@ void Box2DBody2D::apply_force(const Vector2 &p_force, const Vector2 &p_position)
ERR_FAIL_COND(!box2d::is_handle_valid(space_handle));
ERR_FAIL_COND(!box2d::is_handle_valid(body_handle));
b2Vec2 force = { p_force.x * last_delta, p_force.y * last_delta };
b2Vec2 pos = { p_position.x, p_position.y };
Vector2 point_centered = get_transform().get_origin() + p_position + get_center_of_mass();
b2Vec2 pos = { point_centered.x, point_centered.y };
box2d::body_apply_impulse_at_point(space_handle, body_handle, force, pos);
}

Expand Down

0 comments on commit b33136f

Please sign in to comment.