bevy_xpbd
bevy_xpbd copied to clipboard
weird behavior of a small cube
trafficstars
- create a small cube and an infinite plane
- wait until cube settles down and sleeps
- throw it into the air with bevy_inspector_egui
after it comes back to the ground, 3 weird things start happening:
- cube is constantly sliding on the ground (all physics engines do that to some extent, don't know why)
- occasionally, cube goes to sleep for 1 frame, then wakes up
- occasionally, cube jumps upwards/rotates by itself (with f32 precision, it flies away, but with f64 it comes back down to continue her dance)
I'm using cube size=0.02. With size=0.2 effect is still there, but less noticeable. Friction is default (=0.3, avg).
See demo here: https://www.youtube.com/watch?v=z_ke6jVr-BE
bevy = "0.11.3"
bevy-inspector-egui = "0.20.0"
bevy_xpbd_3d = { git = "https://github.com/Jondolf/bevy_xpbd", branch = "main", features = ["debug-plugin", "f64", "3d", "collider-from-mesh"], default-features = false }
use bevy::math::DVec3;
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_xpbd_3d::prelude as xpbd;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(xpbd::PhysicsPlugins::default())
.add_plugins(WorldInspectorPlugin::new())
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.3, 0.3, 1.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
commands.spawn((
xpbd::RigidBody::Static,
xpbd::Collider::halfspace(DVec3::Y),
xpbd::Restitution::new(0.7),
));
commands.spawn((
xpbd::RigidBody::Dynamic,
SpatialBundle::from_transform(
Transform::from_xyz(0.1, 0.8, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
),
xpbd::Collider::cuboid(0.02, 0.02, 0.02),
));
}