got two wheels working pretty good

next step is to make the wheels have friction and to rotate
This commit is contained in:
Joe Ardent 2023-01-28 16:46:24 -08:00
parent 2436e27290
commit e524decd38
5 changed files with 81 additions and 86 deletions

90
Cargo.lock generated
View file

@ -37,9 +37,9 @@ dependencies = [
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.8.2" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@ -949,9 +949,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.78" version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]] [[package]]
name = "cesu8" name = "cesu8"
@ -1303,16 +1303,16 @@ version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65a5e883a316e53866977450eecfbcac9c48109c2ab3394af29feb83fcde4ea9" checksum = "65a5e883a316e53866977450eecfbcac9c48109c2ab3394af29feb83fcde4ea9"
dependencies = [ dependencies = [
"ahash 0.8.2", "ahash 0.8.3",
"epaint", "epaint",
"nohash-hasher", "nohash-hasher",
] ]
[[package]] [[package]]
name = "either" name = "either"
version = "1.8.0" version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]] [[package]]
name = "emath" name = "emath"
@ -1372,7 +1372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de14b65fe5e423e0058f77a8beb2c863b056d0566d6c4ce0d097aa5814cb705a" checksum = "de14b65fe5e423e0058f77a8beb2c863b056d0566d6c4ce0d097aa5814cb705a"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash 0.8.2", "ahash 0.8.3",
"atomic_refcell", "atomic_refcell",
"bytemuck", "bytemuck",
"ecolor", "ecolor",
@ -1891,12 +1891,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "libm"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.6" version = "0.2.6"
@ -2176,6 +2170,15 @@ dependencies = [
"rand_xorshift", "rand_xorshift",
] ]
[[package]]
name = "nom8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.46.0"
@ -2234,23 +2237,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm 0.2.6", "libm",
] ]
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.5.7" version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b"
dependencies = [ dependencies = [
"num_enum_derive", "num_enum_derive",
] ]
[[package]] [[package]]
name = "num_enum_derive" name = "num_enum_derive"
version = "0.5.7" version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2324,16 +2327,6 @@ dependencies = [
"ttf-parser", "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]] [[package]]
name = "parking" name = "parking"
version = "2.0.0" version = "2.0.0"
@ -2447,19 +2440,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "pretty-type-name" name = "pretty-type-name"
version = "1.0.0" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" checksum = "f0f73cdaf19b52e6143685c3606206e114a4dfa969d6b14ec3894c88eb38bd4b"
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.2.1" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"thiserror", "toml_edit",
"toml",
] ]
[[package]] [[package]]
@ -2539,9 +2531,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
[[package]] [[package]]
name = "rapier3d" name = "rapier3d"
version = "0.17.0" version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8aa1871dbbf25b2d91832c5f426827defc648d5340607870dc05471ab2748522" checksum = "33c3a4adb69feadac44d74be058aaaec4502f9c193ec20c0e629b07387ee61a2"
dependencies = [ dependencies = [
"approx", "approx",
"arrayvec", "arrayvec",
@ -2555,7 +2547,6 @@ dependencies = [
"parry3d", "parry3d",
"rustc-hash", "rustc-hash",
"simba", "simba",
"vec_map",
] ]
[[package]] [[package]]
@ -2748,7 +2739,6 @@ dependencies = [
"approx", "approx",
"num-complex", "num-complex",
"num-traits", "num-traits",
"packed_simd_2",
"paste", "paste",
"wide", "wide",
] ]
@ -2923,6 +2913,23 @@ dependencies = [
"serde", "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]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.37" version = "0.1.37"
@ -3181,9 +3188,9 @@ dependencies = [
[[package]] [[package]]
name = "webbrowser" name = "webbrowser"
version = "0.8.4" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74f5ff7786c4c21f61ba8e30ea29c9745f06fca0a4a02d083b3c662583399e8" checksum = "769f1a8831de12cad7bd6f9693b15b1432d93a151557810f617f626af823acae"
dependencies = [ dependencies = [
"core-foundation", "core-foundation",
"dirs", "dirs",
@ -3194,7 +3201,6 @@ dependencies = [
"raw-window-handle 0.5.0", "raw-window-handle 0.5.0",
"url", "url",
"web-sys", "web-sys",
"windows",
] ]
[[package]] [[package]]

View file

@ -28,7 +28,7 @@ features = [
] ]
[dependencies.bevy_rapier3d] [dependencies.bevy_rapier3d]
features = ["simd-nightly", "debug-render-3d"] features = ["debug-render-3d"]
version = "0.20" version = "0.20"
# Maybe also enable only a small amount of optimization for our code: # Maybe also enable only a small amount of optimization for our code:

View file

@ -11,7 +11,8 @@ use crate::{
input::InputState, input::InputState,
}; };
#[derive(Resource)] #[derive(Debug, Resource, Reflect)]
#[reflect(Resource)]
pub struct MovementSettings { pub struct MovementSettings {
pub accel: f32, pub accel: f32,
pub gravity: f32, pub gravity: f32,
@ -21,9 +22,9 @@ pub struct MovementSettings {
impl Default for MovementSettings { impl Default for MovementSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
sensitivity: 10.0, sensitivity: 6.0,
accel: 20.0, accel: 40.0,
gravity: 9.8, gravity: 5.0,
} }
} }
} }
@ -113,8 +114,10 @@ fn input_forces(
friction.coefficient = if input.brake { 2.0 } else { 0.0 }; friction.coefficient = if input.brake { 2.0 } else { 0.0 };
// steering // steering
let torque = xform.down() * input.yaw * settings.sensitivity; let force = xform.right() * input.yaw * settings.sensitivity;
forces.torque += torque; 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>>) { fn drag(mut query: Query<(&Velocity, &mut ExternalForce), With<CyberBikeBody>>) {
@ -130,6 +133,7 @@ pub struct CyberActionPlugin;
impl Plugin for CyberActionPlugin { impl Plugin for CyberActionPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<MovementSettings>() app.init_resource::<MovementSettings>()
.register_type::<MovementSettings>()
.init_resource::<CatControllerSettings>() .init_resource::<CatControllerSettings>()
.register_type::<CatControllerSettings>() .register_type::<CatControllerSettings>()
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default()) .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())

View file

@ -5,7 +5,7 @@ use bevy_rapier3d::{
geometry::Group, geometry::Group,
prelude::{ prelude::{
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction, Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
ImpulseJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping, MultibodyJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping,
TransformInterpolation, Velocity, TransformInterpolation, Velocity,
}, },
}; };
@ -54,11 +54,11 @@ impl Default for WheelConfig {
front_forward: 0.9, front_forward: 0.9,
front_stance: 0.65, front_stance: 0.65,
rear_back: 1.1, rear_back: 1.1,
y: -1.5, y: -0.4,
limits: [-1.0, 0.0], limits: [-0.5, 0.1],
stiffness: 80.0, stiffness: 75.0,
damping: 0.6, damping: 2.0,
radius: 0.4, radius: 0.3,
} }
} }
} }
@ -147,6 +147,7 @@ fn spawn_cyberbike(
spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials); spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
} }
#[cfg(feature = "inspector")]
fn re_tire( fn re_tire(
mut commands: Commands, mut commands: Commands,
wheel_conf: ResMut<WheelConfig>, wheel_conf: ResMut<WheelConfig>,
@ -171,6 +172,7 @@ fn spawn_tires(
conf: &WheelConfig, conf: &WheelConfig,
meshterials: &mut Meshterial, meshterials: &mut Meshterial,
) { ) {
//return;
// re-set the collision group // re-set the collision group
let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP; let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP;
let wheels_collision_group = CollisionGroups::new(membership, filter); let wheels_collision_group = CollisionGroups::new(membership, filter);
@ -204,19 +206,11 @@ fn spawn_tires(
..Default::default() ..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_x = 0.0;
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_z = -conf.front_forward; let wheel_z = -conf.front_forward;
let offset = Vec3::new(wheel_x, wheel_y, wheel_z); let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
wheel_poses.push(offset); wheel_poses.push(offset);
@ -244,8 +238,8 @@ fn spawn_tires(
let prismatic = PrismaticJointBuilder::new(Vec3::Y) let prismatic = PrismaticJointBuilder::new(Vec3::Y)
.local_anchor1(offset) .local_anchor1(offset)
.limits(limits) .limits(limits)
.motor_position(-1.0, stiffness, damping); .motor_position(-0.1, stiffness, damping);
let joint = ImpulseJoint::new(bike, prismatic); let joint = MultibodyJoint::new(bike, prismatic);
let spatial_bundle = SpatialBundle { let spatial_bundle = SpatialBundle {
transform: wheel_pos_in_world, transform: wheel_pos_in_world,
@ -290,7 +284,11 @@ impl Plugin for CyberBikePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(WheelConfig::default()) app.insert_resource(WheelConfig::default())
.register_type::<WheelConfig>() .register_type::<WheelConfig>()
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike) .add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike);
.add_system(re_tire);
#[cfg(feature = "inspector")]
{
app.add_system(re_tire);
}
} }
} }

View file

@ -1,20 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
use cyber_rider::{ use cyber_rider::{
action::{CyberActionPlugin, MovementSettings}, action::CyberActionPlugin, bike::CyberBikePlugin, camera::CyberCamPlugin, disable_mouse_trap,
bike::CyberBikePlugin, glamor::CyberGlamorPlugin, input::CyberInputPlugin, lights::CyberSpaceLightsPlugin,
camera::CyberCamPlugin, planet::CyberPlanetPlugin, ui::CyberUIPlugin,
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,
}; };
fn main() { fn main() {
@ -29,7 +17,6 @@ fn main() {
}, },
..Default::default() ..Default::default()
})) }))
.insert_resource(MOVEMENT_SETTINGS)
.add_plugin(CyberPlanetPlugin) .add_plugin(CyberPlanetPlugin)
.add_plugin(CyberGlamorPlugin) .add_plugin(CyberGlamorPlugin)
.add_plugin(CyberInputPlugin) .add_plugin(CyberInputPlugin)