Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting pixels_per_meter doesn't seem to affect the physics scale #459

Open
royvandewater opened this issue Dec 11, 2023 · 2 comments
Open
Labels
D-Medium documentation Improvements or additions to documentation P-Low S-not-started Work has not started

Comments

@royvandewater
Copy link

I think I might be misunderstanding what this value does. When running the boxes2 example, there seems to be no difference between adjusting the pixels_per_meter value. I have tried using a value of 1.0, 100.0 (default), and 10000.0 and the simulations seem to run exactly the same.

From Common Mistakes: Why is Everything Moving in Slow Motion docs, I got the impression that the pixels_per_meter constructor would adjust the simulation scale. I was expecting that a value of 1.0 would cause the boxes to fall a lot slower (since they'd be bigger and have further to fall) and I was expecting a value of 10000.0 to cause the boxes to fall a lot faster, since they'd be smaller and much closer to the ground.

@royvandewater
Copy link
Author

I tried adjusting the physics scale by calling .with_physics_scale() with different values ranging from 0.2 to 2000.0, but it also seemed to have no impact.

@GinjaNinja32
Copy link

that example is using the default gravity, with a fixed magnitude of 98.1 (vs 9.81 for 3D), which gets interpreted in scale units; due to how this value is set (in RapierConfiguration::default()), it can't take into account the varying scales that might be set; if you edit the example to apply the scale to the gravity too, the boxes act how you expected them to;

diff --git a/bevy_rapier2d/examples/boxes2.rs b/bevy_rapier2d/examples/boxes2.rs
index 6de77dd..1276491 100644
--- a/bevy_rapier2d/examples/boxes2.rs
+++ b/bevy_rapier2d/examples/boxes2.rs
@@ -1,6 +1,8 @@
 use bevy::prelude::*;
 use bevy_rapier2d::prelude::*;

+const SCALE: f32 = 10.0;
+
 fn main() {
     App::new()
         .insert_resource(ClearColor(Color::rgb(
@@ -10,7 +12,7 @@ fn main() {
         )))
         .add_plugins((
             DefaultPlugins,
-            RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0),
+            RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(SCALE),
             RapierDebugRenderPlugin::default(),
         ))
         .add_systems(Startup, (setup_graphics, setup_physics))
@@ -24,7 +26,9 @@ pub fn setup_graphics(mut commands: Commands) {
     });
 }

-pub fn setup_physics(mut commands: Commands) {
+pub fn setup_physics(mut commands: Commands, mut rapier_config: ResMut<RapierConfiguration>) {
+    rapier_config.gravity = -Vect::Y * 9.81 * SCALE;
+
     /*
      * Ground
      */

effectively, the boxes are tiny with scale=10000.0, but the default gravity is weaker by the same amount and it cancels out.

@Vrixyz Vrixyz added documentation Improvements or additions to documentation D-Medium P-Low S-not-started Work has not started labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-Medium documentation Improvements or additions to documentation P-Low S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

3 participants