Skip to content

Commit

Permalink
Redo impulse to not use mass (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu authored Apr 4, 2024
1 parent 5b90c3b commit 815ab56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/web_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Emscripten latest
uses: mymindstorm/setup-emsdk@v12
with:
version: 3.1.45
version: 3.1.39
no-cache: true

- name: Verify Emscripten setup
Expand Down
12 changes: 5 additions & 7 deletions src/bodies/rapier_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ void RapierBody2D::set_force_integration_callback(const Callable &p_callable, co
}

void RapierBody2D::apply_central_impulse(const Vector2 &p_impulse) {
Vector2 mass_impulse = p_impulse * mass;
if (!get_space()) {
impulse += mass_impulse;
impulse += p_impulse;
return;
}

Expand All @@ -647,15 +646,14 @@ void RapierBody2D::apply_central_impulse(const Vector2 &p_impulse) {
ERR_FAIL_COND(!rapier2d::is_handle_valid(space_handle));

ERR_FAIL_COND(!rapier2d::is_handle_valid(body_handle));
rapier2d::Vector impulse = { mass_impulse.x, mass_impulse.y };
rapier2d::Vector impulse = { p_impulse.x, p_impulse.y };
rapier2d::body_apply_impulse(space_handle, body_handle, &impulse);
}

void RapierBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) {
Vector2 mass_impulse = p_impulse * mass;
if (!get_space()) {
impulse += mass_impulse;
torque += (p_position - get_center_of_mass()).cross(mass_impulse);
impulse += p_impulse;
torque += (p_position - get_center_of_mass()).cross(p_impulse);
return;
}

Expand All @@ -668,7 +666,7 @@ void RapierBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_posi
ERR_FAIL_COND(!rapier2d::is_handle_valid(space_handle));

ERR_FAIL_COND(!rapier2d::is_handle_valid(body_handle));
rapier2d::Vector impulse = { mass_impulse.x, mass_impulse.y };
rapier2d::Vector impulse = { p_impulse.x, p_impulse.y };
rapier2d::Vector pos = { p_position.x, p_position.y };
rapier2d::body_apply_impulse_at_point(space_handle, body_handle, &impulse, &pos);
}
Expand Down

0 comments on commit 815ab56

Please sign in to comment.