Make bike model, body, and collider explicit, add debug collider viz.

This commit is contained in:
Joe Ardent 2022-02-26 23:31:01 -08:00
parent 37e8e40c3f
commit 5b4b526aaf
7 changed files with 55 additions and 41 deletions

14
Cargo.lock generated
View file

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ab_glyph"
version = "0.2.13"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61caed9aec6daeee1ea38ccf5fb225e4f96c1eeead1b4a5c267324a63cf02326"
checksum = "d54a65e0d4f66f8536c98cb3ca81ca33b7e2ca43442465507a3a62291ec0d9e4"
dependencies = [
"ab_glyph_rasterizer",
"owned_ttf_parser",
@ -461,8 +461,6 @@ dependencies = [
[[package]]
name = "bevy_rapier3d"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5186c735d7aa202e982f93c71b444d34bf15fed44aca942f9b5f2940e3d06764"
dependencies = [
"bevy",
"nalgebra",
@ -2010,9 +2008,9 @@ checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "owned_ttf_parser"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef05f2882a8b3e7acc10c153ade2631f7bfc8ce00d2bf3fb8f4e9d2ae6ea5c3"
checksum = "4fb1e509cfe7a12db2a90bfa057dfcdbc55a347f5da677c506b53dd099cfec9d"
dependencies = [
"ttf-parser",
]
@ -2757,9 +2755,9 @@ dependencies = [
[[package]]
name = "ttf-parser"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccbe8381883510b6a2d8f1e32905bddd178c11caef8083086d0c0c9ab0ac281"
checksum = "c74c96594835e10fa545e2a51e8709f30b173a092bfd6036ef2cec53376244f3"
[[package]]
name = "typenum"

View file

@ -24,8 +24,9 @@ features = [
]
[dependencies.bevy_rapier3d]
version = "0.12"
path = "../bevy_rapier/bevy_rapier3d"
features = ["parallel", "simd-nightly"]
# version = "0.12"
# Maybe also enable only a small amount of optimization for our code:
[profile.dev]

View file

@ -1,7 +1,10 @@
use bevy::prelude::*;
use bevy_rapier3d::{na::Vector3, prelude::*};
use crate::{geometry::CyberBike, input::InputState};
use crate::{
colliders::{CyberBikeBody, CyberBikeCollider},
input::InputState,
};
pub struct MovementSettings {
pub sensitivity: f32,
@ -20,7 +23,7 @@ impl Default for MovementSettings {
}
fn gravity(
xform: Query<&Transform, With<CyberBike>>,
xform: Query<&Transform, With<CyberBikeBody>>,
settings: Res<MovementSettings>,
mut config: ResMut<RapierConfiguration>,
) {
@ -29,7 +32,7 @@ fn gravity(
}
fn falling_cat(
mut bike_query: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBike>>,
mut bike_query: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBikeBody>>,
) {
let (bike_xform, mut forces) = bike_query.single_mut();
let up = bike_xform.translation.normalize();
@ -44,7 +47,10 @@ fn falling_cat(
}
fn drag(
mut query: Query<(&RigidBodyVelocityComponent, &mut RigidBodyForcesComponent), With<CyberBike>>,
mut query: Query<
(&RigidBodyVelocityComponent, &mut RigidBodyForcesComponent),
With<CyberBikeBody>,
>,
) {
let (vels, mut forces) = query.single_mut();
@ -57,16 +63,11 @@ fn drag(
fn input_forces(
settings: Res<MovementSettings>,
input: Res<InputState>,
mut query: Query<
(
&Transform,
&mut RigidBodyForcesComponent,
&mut ColliderMaterialComponent,
),
With<CyberBike>,
>,
mut cquery: Query<&mut ColliderMaterialComponent, With<CyberBikeCollider>>,
mut bquery: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBikeBody>>,
) {
let (xform, mut forces, mut cmat) = query.single_mut();
let (xform, mut forces) = bquery.single_mut();
let mut cmat = cquery.single_mut();
// thrust
let thrust: Vector3<f32> = (xform.forward() * input.throttle * settings.accel).into();

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
use crate::{
geometry::{CyberBike, SPAWN_ALTITUDE},
geometry::{CyberBikeModel, SPAWN_ALTITUDE},
input::InputState,
};
@ -29,8 +29,8 @@ fn setup_cybercam(mut commands: Commands) {
}
fn follow_cyberbike(
bike_query: Query<&Transform, (Without<CyberCam>, With<CyberBike>)>,
mut cam_query: Query<&mut Transform, (With<CyberCam>, Without<CyberBike>)>,
bike_query: Query<&Transform, (Without<CyberCam>, With<CyberBikeModel>)>,
mut cam_query: Query<&mut Transform, (With<CyberCam>, Without<CyberBikeModel>)>,
input: Res<InputState>,
) {
let bike_xform = bike_query.single();

View file

@ -4,13 +4,19 @@ use bevy::{
};
use bevy_rapier3d::prelude::*;
use crate::geometry::{CyberBike, CyberSphere, PLANET_RADIUS, SPAWN_ALTITUDE};
use crate::geometry::{CyberBikeModel, CyberSphere, PLANET_RADIUS, SPAWN_ALTITUDE};
#[derive(Component)]
pub struct CyberBikeBody;
#[derive(Component)]
pub struct CyberBikeCollider;
fn setup_colliders(
mut commands: Commands,
meshes: Res<Assets<Mesh>>,
planet_query: Query<(Entity, &Handle<Mesh>), With<CyberSphere>>,
bike_query: Query<(Entity, &Transform), With<CyberBike>>,
bike_query: Query<(Entity, &Transform), With<CyberBikeModel>>,
) {
let (planet, mesh_handle) = planet_query.single();
@ -85,9 +91,9 @@ fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands)
bbody.position = isometry.into();
// collider
let shape = ColliderShape::capsule(
Vec3::new(0.0, 0.0, -1.25).into(),
Vec3::new(0.0, 0.0, 1.25).into(),
0.4,
Vec3::new(0.0, 0.0, -5.25).into(),
Vec3::new(0.0, 0.0, 5.25).into(),
5.2,
);
let bcollide = ColliderBundle {
shape: shape.into(),
@ -103,15 +109,23 @@ fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands)
commands
.entity(bike)
.insert_bundle(bbody)
.insert_bundle(bcollide)
.insert(CyberBikeBody)
.insert(RigidBodyPositionSync::Discrete)
.with_children(|e| {
e.spawn_bundle(bcollide)
.insert(ColliderDebugRender {
color: Color::GREEN,
})
.insert(CyberBikeCollider)
.insert(ColliderPositionSync::Discrete);
});
}
pub struct CyberCollidersPlugin;
impl Plugin for CyberCollidersPlugin {
fn build(&self, app: &mut App) {
//
app.add_startup_system_to_stage(
app.add_plugin(RapierRenderPlugin)
.add_startup_system_to_stage(
StartupStage::PostStartup,
setup_colliders.label("colliders"),
);

View file

@ -12,7 +12,7 @@ pub const PLANET_RADIUS: f32 = 5000.0;
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015;
#[derive(Component, Debug)]
pub struct CyberBike;
pub struct CyberBikeModel;
#[derive(Component)]
pub struct CyberSphere;
@ -59,7 +59,7 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_children(|rider| {
rider.spawn_scene(asset_server.load("cyber-bike_no_y_up.glb#Scene0"));
})
.insert(CyberBike);
.insert(CyberBikeModel);
}
pub struct CyberGeomPlugin;

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use crate::geometry::CyberBike;
use crate::colliders::CyberBikeBody;
#[derive(Component)]
struct UpText;
@ -34,7 +34,7 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
}
fn update_ui(
state_query: Query<&RigidBodyVelocityComponent, With<CyberBike>>,
state_query: Query<&RigidBodyVelocityComponent, With<CyberBikeBody>>,
mut text_query: Query<&mut Text, With<UpText>>,
) {
let mut text = text_query.single_mut();