Skip to content

Instantly share code, notes, and snippets.

@atlv24
Created September 5, 2022 23:14
Show Gist options
  • Save atlv24/1c524f734cc109946f12a4294a2f5b5e to your computer and use it in GitHub Desktop.
Save atlv24/1c524f734cc109946f12a4294a2f5b5e to your computer and use it in GitHub Desktop.
Minimal repro for physics jitter
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use std::f32::consts::TAU;
fn main()
{
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugin(RapierDebugRenderPlugin::default())
.add_startup_system(setup)
.add_startup_system(move |mut rapier: ResMut<RapierContext>| {
rapier.integration_parameters.erp = 0.7; // 0.8 is default.
})
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: Commands,
)
{
let indices = vec![
[0, 2, 1], [3, 0, 1], [4, 2, 0], [5, 0, 3], [6, 4, 0], [7, 0, 5],
[8, 6, 0], [8, 0, 7], [18, 8, 10], [12, 2, 4], [18, 6, 8], [17, 15, 5],
[12, 4, 14], [17, 3, 13], [13, 3, 1], [21, 9, 11], [19, 7, 5], [20, 10, 8],
[17, 5, 3], [12, 11, 2], [13, 1, 9], [19, 5, 15], [29, 17, 13], [16, 14, 4],
[18, 16, 6], [16, 4, 6], [11, 9, 1], [11, 1, 2], [20, 7, 19], [26, 17, 29],
[20, 8, 7], [25, 30, 16], [26, 15, 17], [29, 13, 23], [28, 16, 18], [23, 13, 21],
[21, 13, 9], [22, 21, 11], [24, 22, 11], [30, 24, 12], [26, 19, 15], [24, 11, 12],
[30, 12, 14], [28, 25, 16], [27, 19, 26], [30, 14, 16], [31, 19, 27], [31, 20, 19],
[32, 28, 18], [32, 20, 31], [32, 18, 10], [32, 10, 20], [36, 23, 21], [35, 34, 22],
[34, 21, 22], [35, 22, 24], [38, 23, 36], [39, 27, 26], [38, 29, 23], [33, 37, 25],
[35, 24, 30], [38, 26, 29], [40, 32, 31], [49, 38, 36], [33, 28, 32], [37, 30, 25],
[46, 35, 30], [33, 25, 28], [40, 27, 39], [51, 40, 39], [40, 31, 27], [46, 30, 37],
[50, 47, 38], [41, 21, 34], [44, 33, 32], [41, 36, 21], [43, 41, 34], [45, 35, 46],
[43, 34, 35], [48, 37, 33], [43, 42, 41], [47, 26, 38], [49, 41, 42], [47, 39, 26],
[50, 38, 49], [49, 36, 41], [48, 45, 46], [45, 43, 35], [44, 32, 40], [48, 46, 37],
[51, 47, 50], [51, 39, 47], [52, 48, 33], [52, 40, 51], [52, 33, 44], [52, 44, 40],
[53, 50, 49], [53, 45, 48], [53, 43, 45], [53, 49, 42], [53, 42, 43], [53, 52, 51],
[53, 48, 52], [53, 51, 50]];
let positions = Vec::from([
[-5, 0, 0], [-4, -3, 0], [-4, -2, -2], [-4, -2, 2], [-4, 0, -3], [-4, 0, 3],
[-4, 2, -2], [-4, 2, 2], [-4, 3, 0], [-3, -4, 0], [-3, 4, 0], [-2, -4, -2],
[-2, -2, -4], [-2, -4, 2], [-3, 0, -4], [-3, 0, 4], [-2, 2, -4], [-2, -2, 4],
[-2, 4, -2], [-2, 2, 4], [-2, 4, 2], [0, -5, 0], [0, -4, -3], [0, -4, 3],
[0, -3, -4], [0, 3, -4], [0, 0, 5], [0, 3, 4], [0, 4, -3], [0, -3, 4],
[0, 0, -5], [0, 4, 3], [0, 5, 0], [2, 4, -2], [2, -4, -2], [2, -2, -4],
[2, -4, 2], [2, 2, -4], [2, -2, 4], [2, 2, 4], [2, 4, 2], [3, -4, 0],
[4, -3, 0], [4, -2, -2], [3, 4, 0], [4, 0, -3], [3, 0, -4], [3, 0, 4],
[4, 2, -2], [4, -2, 2], [4, 0, 3], [4, 2, 2], [4, 3, 0], [5, 0, 0]]
.map(|v| Vect::from_array(v.map(|a| a as f32))));
commands
.spawn_bundle(Camera3dBundle {
transform: Transform::from_xyz(0.0, 5.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
commands
.spawn()
.insert(RigidBody::Dynamic)
.insert(Collider::convex_mesh(positions, &indices).unwrap())
.insert_bundle(TransformBundle::from(Transform::from_xyz(0.0, 10.0, 0.0)));
commands
.spawn()
.insert(RigidBody::Dynamic)
.insert(Collider::cone(2.0,1.0))
.insert_bundle(TransformBundle::from(Transform::from_xyz(2.0, 20.0, 0.0).with_rotation(Quat::from_axis_angle(Vec3::Z, TAU/2.0))));
commands
.spawn()
.insert(RigidBody::Fixed)
.insert(Collider::cuboid(50.0,0.5,50.0))
.insert_bundle(TransformBundle::from(Transform::from_xyz(0.0, 0.0, 0.0)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment