Skip to content

TimestepMode::Fixed has framerate-dependent behavior #676

@Hades948

Description

@Hades948

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::<NoUserData>::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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions