dimforge / dimforge/bevy_rapier

Why is the speed of the ball not constant in this demo?

Open
#522 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

### system:
macmini m2

### cargo.toml version:
bevy = "0.13.2"
bevy_rapier2d = { version = "0.26.0", features = [ "simd-stable", "debug-render-2d" ] }

### code:
```rust
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy_rapier2d::prelude::*;

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

fn debug_print(query: Query<&Velocity, With>) {
let velocity = query.single();
println!("{velocity:?}");
}

#[derive(Component)]
struct Ball;

#[derive(Component)]
struct Wall;

fn setup(
mut commands: Commands,
mut material: ResMut>,
mut meshes: ResMut>,
) {
commands.spawn(Camera2dBundle::default());

commands.spawn((
Ball,
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(Circle::new(20.0))).into(),
material: material.add(Color::RED),
..default()
},
RigidBody::Dynamic,
Collider::ball(20.0),
Restitution::coefficient(1.0),
Friction::coefficient(0.0),
GravityScale(0.0),
Velocity {
linvel: Vec2::new(500.0, 300.0),
..default()
},
));

commands.spawn((
Wall,
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(Rectangle::new(800.0, 10.0))).into(),
material: material.add(Color::LIME_GREEN),
transform: Transform::from_xyz(0.0, 300.0, 0.0),
..default()
},
RigidBody::Fixed,
Collider::cuboid(400.0, 5.0),
Restitution::coefficient(1.0),
Friction::coefficient(0.0),
));

commands.spawn((
Wall,
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(Rectangle::new(800.0, 10.0))).into(),
material: material.add(Color::LIME_GREEN),
transform: Transform::from_xyz(0.0, -300.0, 0.0),
..default()
},
RigidBody::Fixed,
Collider::cuboid(400.0, 5.0),
Restitution::coefficient(1.0),
Friction::coefficient(0.0),
));

commands.spawn((
Wall,
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(Rectangle::new(10.0, 600.0))).into(),
material: material.add(Color::LIME_GREEN),
transform: Transform::from_xyz(400.0, 0.0, 0.0),
..default()
},
RigidBody::Fixed,
Collider::cuboid(5.0, 300.0),
Restitution::coefficient(1.0),
Friction::coefficient(0.0),
));

commands.spawn((
Wall,
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(Rectangle::new(10.0, 600.0))).into(),
material: material.add(Color::LIME_GREEN),
transform: Transform::from_xyz(-400.0, 0.0, 0.0),
..default()
},
RigidBody::Fixed,
Collider::cuboid(5.0, 300.0),
Restitution::coefficient(1.0),
Friction::coefficient(0.0),
));
}
```

### expect:
the speed of the printed ball is constant

### result:
The ball's speed changes after multiple collisions with the wall.

### print log:
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }
Velocity { linvel: Vec2(366.13907, 300.00055), angvel: 0.0 }

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.