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

Rotating kinematic collider jitters when rotation approaches zero #217

Open
irate-devil opened this issue Nov 1, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@irate-devil
Copy link

irate-devil commented Nov 1, 2023

In the following example the platform jitters whenever it gets close to being horizontal, usually giving the boxes a bump and sometimes causing them to explode.

The platform's jitter is quite visible when you look at the corners.

This appears to only affect bevy_xpbd_2d.

use bevy::prelude::*;
use bevy_xpbd_2d::{math::*, prelude::*};

fn main() {
    App::new()
        .insert_resource(Gravity(Vector::NEG_Y * 1000.0))
        .add_plugins((
            DefaultPlugins,
            PhysicsPlugins::default(),
            PhysicsDebugPlugin::default(),
        ))
        .add_systems(Startup, setup)
        .add_systems(Update, rotate_platform)
        .run();
}

#[derive(Component)]
struct Platform;

fn rotate_platform(mut platform: Query<&mut Transform, With<Platform>>, time: Res<Time>) {
    for mut transform in &mut platform {
        transform.rotation = Quat::from_rotation_z(time.elapsed_seconds().cos() * 0.1);
    }
}

fn setup(mut commands: Commands) {
    // Platform
    commands.spawn((
        Platform,
        TransformBundle::from(Transform::from_xyz(0., -320., 0.)),
        RigidBody::Kinematic,
        Collider::cuboid(800., 40.),
    ));

    // Boxes
    for x in -3..4 {
        for y in -2..4 {
            commands.spawn((
                TransformBundle::from(Transform::from_xyz(x as f32 * 101., y as f32 * 101., 0.)),
                RigidBody::Dynamic,
                Collider::cuboid(100., 100.),
            ));
        }
    }

    commands.spawn(Camera2dBundle::default());
}
@Jondolf Jondolf added the bug Something isn't working label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants