dimforge / dimforge/bevy_rapier

TimestepMode::Fixed has framerate-dependent behavior

Open
#676 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.6k
Forks
282
PR merge metrics
No merged PRs in 30d

Description

It's possible this is a duplicate of #475, so feel free to close if it is. But it seemed different enough to me that I'd open a different issue.

The example below just spawns a square that moves to the right with a linear velocity of 50.0. When I run it on my 144 Hz monitor, the square goes much quicker than when I run it on my 60 Hz monitor. I had noticed this for a lot of the velocities in my game, so I made this smaller demo to help demonstrate what I'm seeing. Am I misunderstanding how fixed timestep works? I thought adding a fixed timestep should keep things framerate-independent. But I'm noticing the opposite. I tried looking online for an answer and posting in the Bevy Discord, but I couldn't find anything beyond "you should be using the FixedUpdate schedule instead of the Update schedule." But this example doesn't even have any updates, it just sets the velocity at the start and that's it.

### main.rs
```
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(RapierPhysicsPlugin::::pixels_per_meter(100.0))
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
) {
commands.insert_resource(TimestepMode::Fixed {
dt: 1.0 / 30.0,
substeps: 1,
});

// Camera
commands.spawn((
Name::new("Camera"),
Camera2d,
Projection::Orthographic(OrthographicProjection {
scale: 0.3,
..OrthographicProjection::default_2d()
}),
));

// Square
commands.spawn((
RigidBody::Dynamic,
GravityScale(0.0),
Velocity {
linvel: Vec2::new(50.0, 0.0),
..default()
},
Sprite {
custom_size: Some(Vec2::splat(10.0)),
..default()
},
));
}
```

### Cargo.toml
```
[package]
name = "physics_demo"
version = "0.1.0"
edition = "2024"

[dependencies]
bevy = "0.16"
bevy_rapier2d = "0.31"
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.