Merge branch 'two-wheels-good'
This commit is contained in:
commit
ec2a99e239
6 changed files with 83 additions and 92 deletions
90
Cargo.lock
generated
90
Cargo.lock
generated
|
@ -37,9 +37,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.2"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107"
|
||||
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
|
@ -949,9 +949,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.78"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
|
||||
[[package]]
|
||||
name = "cesu8"
|
||||
|
@ -1303,16 +1303,16 @@ version = "0.20.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65a5e883a316e53866977450eecfbcac9c48109c2ab3394af29feb83fcde4ea9"
|
||||
dependencies = [
|
||||
"ahash 0.8.2",
|
||||
"ahash 0.8.3",
|
||||
"epaint",
|
||||
"nohash-hasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "emath"
|
||||
|
@ -1372,7 +1372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "de14b65fe5e423e0058f77a8beb2c863b056d0566d6c4ce0d097aa5814cb705a"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"ahash 0.8.2",
|
||||
"ahash 0.8.3",
|
||||
"atomic_refcell",
|
||||
"bytemuck",
|
||||
"ecolor",
|
||||
|
@ -1891,12 +1891,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.2.6"
|
||||
|
@ -2176,6 +2170,15 @@ dependencies = [
|
|||
"rand_xorshift",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom8"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
|
@ -2234,23 +2237,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"libm 0.2.6",
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.5.7"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9"
|
||||
checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b"
|
||||
dependencies = [
|
||||
"num_enum_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.5.7"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
|
||||
checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2324,16 +2327,6 @@ dependencies = [
|
|||
"ttf-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packed_simd_2"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libm 0.1.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
version = "2.0.0"
|
||||
|
@ -2447,19 +2440,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
|||
|
||||
[[package]]
|
||||
name = "pretty-type-name"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d"
|
||||
checksum = "f0f73cdaf19b52e6143685c3606206e114a4dfa969d6b14ec3894c88eb38bd4b"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.2.1"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9"
|
||||
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2539,9 +2531,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
|
|||
|
||||
[[package]]
|
||||
name = "rapier3d"
|
||||
version = "0.17.0"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8aa1871dbbf25b2d91832c5f426827defc648d5340607870dc05471ab2748522"
|
||||
checksum = "33c3a4adb69feadac44d74be058aaaec4502f9c193ec20c0e629b07387ee61a2"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"arrayvec",
|
||||
|
@ -2555,7 +2547,6 @@ dependencies = [
|
|||
"parry3d",
|
||||
"rustc-hash",
|
||||
"simba",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2748,7 +2739,6 @@ dependencies = [
|
|||
"approx",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"packed_simd_2",
|
||||
"paste",
|
||||
"wide",
|
||||
]
|
||||
|
@ -2923,6 +2913,23 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"nom8",
|
||||
"toml_datetime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
|
@ -3181,9 +3188,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "webbrowser"
|
||||
version = "0.8.4"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e74f5ff7786c4c21f61ba8e30ea29c9745f06fca0a4a02d083b3c662583399e8"
|
||||
checksum = "769f1a8831de12cad7bd6f9693b15b1432d93a151557810f617f626af823acae"
|
||||
dependencies = [
|
||||
"core-foundation",
|
||||
"dirs",
|
||||
|
@ -3194,7 +3201,6 @@ dependencies = [
|
|||
"raw-window-handle 0.5.0",
|
||||
"url",
|
||||
"web-sys",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -28,7 +28,7 @@ features = [
|
|||
]
|
||||
|
||||
[dependencies.bevy_rapier3d]
|
||||
features = ["simd-nightly", "debug-render-3d"]
|
||||
features = ["debug-render-3d"]
|
||||
version = "0.20"
|
||||
|
||||
# Maybe also enable only a small amount of optimization for our code:
|
||||
|
|
|
@ -11,7 +11,8 @@ use crate::{
|
|||
input::InputState,
|
||||
};
|
||||
|
||||
#[derive(Resource)]
|
||||
#[derive(Debug, Resource, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct MovementSettings {
|
||||
pub accel: f32,
|
||||
pub gravity: f32,
|
||||
|
@ -21,9 +22,9 @@ pub struct MovementSettings {
|
|||
impl Default for MovementSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
sensitivity: 10.0,
|
||||
accel: 20.0,
|
||||
gravity: 9.8,
|
||||
sensitivity: 6.0,
|
||||
accel: 40.0,
|
||||
gravity: 5.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,8 +114,10 @@ fn input_forces(
|
|||
friction.coefficient = if input.brake { 2.0 } else { 0.0 };
|
||||
|
||||
// steering
|
||||
let torque = xform.down() * input.yaw * settings.sensitivity;
|
||||
forces.torque += torque;
|
||||
let force = xform.right() * input.yaw * settings.sensitivity;
|
||||
let point = xform.translation + xform.forward() + Vec3::new(0.5, 0.0, 0.0);
|
||||
let force = ExternalForce::at_point(force, point, xform.translation);
|
||||
*forces += force;
|
||||
}
|
||||
|
||||
fn drag(mut query: Query<(&Velocity, &mut ExternalForce), With<CyberBikeBody>>) {
|
||||
|
@ -130,6 +133,7 @@ pub struct CyberActionPlugin;
|
|||
impl Plugin for CyberActionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<MovementSettings>()
|
||||
.register_type::<MovementSettings>()
|
||||
.init_resource::<CatControllerSettings>()
|
||||
.register_type::<CatControllerSettings>()
|
||||
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
|
|
44
src/bike.rs
44
src/bike.rs
|
@ -5,7 +5,7 @@ use bevy_rapier3d::{
|
|||
geometry::Group,
|
||||
prelude::{
|
||||
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
|
||||
ImpulseJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping,
|
||||
MultibodyJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping,
|
||||
TransformInterpolation, Velocity,
|
||||
},
|
||||
};
|
||||
|
@ -23,9 +23,6 @@ pub struct CyberBikeBody;
|
|||
#[derive(Component)]
|
||||
pub struct CyberBikeCollider;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct CyberBikeModel;
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct CyberWheel;
|
||||
|
||||
|
@ -54,11 +51,11 @@ impl Default for WheelConfig {
|
|||
front_forward: 0.9,
|
||||
front_stance: 0.65,
|
||||
rear_back: 1.1,
|
||||
y: -1.5,
|
||||
limits: [-1.0, 0.0],
|
||||
stiffness: 80.0,
|
||||
damping: 0.6,
|
||||
radius: 0.4,
|
||||
y: -0.4,
|
||||
limits: [-0.5, 0.1],
|
||||
stiffness: 75.0,
|
||||
damping: 2.0,
|
||||
radius: 0.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +136,6 @@ fn spawn_cyberbike(
|
|||
..Default::default()
|
||||
});
|
||||
})
|
||||
.insert(CyberBikeModel)
|
||||
.insert(CyberBikeBody)
|
||||
.insert(CyberBikeControl::default())
|
||||
.id();
|
||||
|
@ -147,6 +143,7 @@ fn spawn_cyberbike(
|
|||
spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
|
||||
}
|
||||
|
||||
#[cfg(feature = "inspector")]
|
||||
fn re_tire(
|
||||
mut commands: Commands,
|
||||
wheel_conf: ResMut<WheelConfig>,
|
||||
|
@ -171,6 +168,7 @@ fn spawn_tires(
|
|||
conf: &WheelConfig,
|
||||
meshterials: &mut Meshterial,
|
||||
) {
|
||||
//return;
|
||||
// re-set the collision group
|
||||
let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP;
|
||||
let wheels_collision_group = CollisionGroups::new(membership, filter);
|
||||
|
@ -204,19 +202,11 @@ fn spawn_tires(
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let mut wheel_poses = Vec::with_capacity(3);
|
||||
let mut wheel_poses = Vec::with_capacity(2);
|
||||
|
||||
// left front
|
||||
// front
|
||||
{
|
||||
let wheel_x = -conf.front_stance;
|
||||
let wheel_z = -conf.front_forward;
|
||||
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
||||
wheel_poses.push(offset);
|
||||
}
|
||||
|
||||
// right front
|
||||
{
|
||||
let wheel_x = conf.front_stance;
|
||||
let wheel_x = 0.0;
|
||||
let wheel_z = -conf.front_forward;
|
||||
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
||||
wheel_poses.push(offset);
|
||||
|
@ -244,8 +234,8 @@ fn spawn_tires(
|
|||
let prismatic = PrismaticJointBuilder::new(Vec3::Y)
|
||||
.local_anchor1(offset)
|
||||
.limits(limits)
|
||||
.motor_position(-1.0, stiffness, damping);
|
||||
let joint = ImpulseJoint::new(bike, prismatic);
|
||||
.motor_position(-0.1, stiffness, damping);
|
||||
let joint = MultibodyJoint::new(bike, prismatic);
|
||||
|
||||
let spatial_bundle = SpatialBundle {
|
||||
transform: wheel_pos_in_world,
|
||||
|
@ -290,7 +280,11 @@ impl Plugin for CyberBikePlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(WheelConfig::default())
|
||||
.register_type::<WheelConfig>()
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike)
|
||||
.add_system(re_tire);
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike);
|
||||
|
||||
#[cfg(feature = "inspector")]
|
||||
{
|
||||
app.add_system(re_tire);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{bike::CyberBikeModel, input::InputState};
|
||||
use crate::{bike::CyberBikeBody, input::InputState};
|
||||
|
||||
// 85 degrees in radians
|
||||
const MAX_PITCH: f32 = 1.48353;
|
||||
|
@ -57,7 +57,7 @@ fn setup_cybercams(mut commands: Commands) {
|
|||
fn follow_cyberbike(
|
||||
mut query: ParamSet<(
|
||||
// 0: the bike
|
||||
Query<&Transform, With<CyberBikeModel>>,
|
||||
Query<&Transform, With<CyberBikeBody>>,
|
||||
// 1: the cameras
|
||||
Query<(&mut Transform, &CyberCameras)>,
|
||||
)>,
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,20 +1,8 @@
|
|||
use bevy::prelude::*;
|
||||
use cyber_rider::{
|
||||
action::{CyberActionPlugin, MovementSettings},
|
||||
bike::CyberBikePlugin,
|
||||
camera::CyberCamPlugin,
|
||||
disable_mouse_trap,
|
||||
glamor::CyberGlamorPlugin,
|
||||
input::CyberInputPlugin,
|
||||
lights::CyberSpaceLightsPlugin,
|
||||
planet::CyberPlanetPlugin,
|
||||
ui::CyberUIPlugin,
|
||||
};
|
||||
|
||||
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
|
||||
sensitivity: 8.0, // steering
|
||||
accel: 30.0, // thrust
|
||||
gravity: 9.0,
|
||||
action::CyberActionPlugin, bike::CyberBikePlugin, camera::CyberCamPlugin, disable_mouse_trap,
|
||||
glamor::CyberGlamorPlugin, input::CyberInputPlugin, lights::CyberSpaceLightsPlugin,
|
||||
planet::CyberPlanetPlugin, ui::CyberUIPlugin,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
|
@ -29,7 +17,6 @@ fn main() {
|
|||
},
|
||||
..Default::default()
|
||||
}))
|
||||
.insert_resource(MOVEMENT_SETTINGS)
|
||||
.add_plugin(CyberPlanetPlugin)
|
||||
.add_plugin(CyberGlamorPlugin)
|
||||
.add_plugin(CyberInputPlugin)
|
||||
|
|
Loading…
Reference in a new issue