Add more wheels and mass.
This commit is contained in:
parent
315f35e8e3
commit
0fc179596a
6 changed files with 54 additions and 25 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -461,7 +461,8 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_rapier3d"
|
name = "bevy_rapier3d"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
source = "git+https://github.com/nebkor/bevy_rapier?branch=debug-render-capsule#3387b8ff9d3615033144cb2e22ad4a965caa6b2b"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5186c735d7aa202e982f93c71b444d34bf15fed44aca942f9b5f2940e3d06764"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
|
@ -2599,9 +2600,9 @@ checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.86"
|
version = "1.0.87"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
checksum = "1e59d925cf59d8151f25a3bedf97c9c157597c9df7324d32d68991cc399ed08b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -26,11 +26,11 @@ features = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies.bevy_rapier3d]
|
[dependencies.bevy_rapier3d]
|
||||||
git = "https://github.com/nebkor/bevy_rapier"
|
#git = "https://github.com/nebkor/bevy_rapier"
|
||||||
#path = "../bevy_rapier/bevy_rapier3d"
|
#path = "../bevy_rapier/bevy_rapier3d"
|
||||||
branch = "debug-render-capsule"
|
#branch = "debug-render-capsule"
|
||||||
features = ["simd-nightly"]
|
features = ["simd-nightly"]
|
||||||
# version = "0.12"
|
version = "0.12"
|
||||||
|
|
||||||
# Maybe also enable only a small amount of optimization for our code:
|
# Maybe also enable only a small amount of optimization for our code:
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|
|
@ -39,11 +39,20 @@ fn falling_cat(
|
||||||
let cam_up = bike_xform.up();
|
let cam_up = bike_xform.up();
|
||||||
let cos = up.dot(cam_up);
|
let cos = up.dot(cam_up);
|
||||||
|
|
||||||
|
let roll_cos = up.dot(bike_xform.right());
|
||||||
|
|
||||||
|
let r_mag = if roll_cos.is_normal() {
|
||||||
|
roll_cos.powi(3) * 8.0
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
let r_tork = bike_xform.forward() * r_mag;
|
||||||
|
|
||||||
let theta = cos.acos();
|
let theta = cos.acos();
|
||||||
let force_mag = if !theta.is_normal() { 0.0 } else { theta * 2.0 };
|
let force_mag = if !theta.is_normal() { 0.0 } else { theta * 7.0 };
|
||||||
let torque = cam_up.cross(up).normalize() * force_mag;
|
let torque = cam_up.cross(up).normalize() * force_mag;
|
||||||
|
|
||||||
forces.torque = torque.into();
|
forces.torque = (r_tork + torque).into();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drag(
|
fn drag(
|
||||||
|
@ -56,7 +65,7 @@ fn drag(
|
||||||
|
|
||||||
if let Some(vel) = vels.linvel.try_normalize(0.001) {
|
if let Some(vel) = vels.linvel.try_normalize(0.001) {
|
||||||
let v2 = vels.linvel.magnitude_squared();
|
let v2 = vels.linvel.magnitude_squared();
|
||||||
forces.force -= vel * v2 * 0.002;
|
forces.force -= vel * v2 * 0.02;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
43
src/bike.rs
43
src/bike.rs
|
@ -3,7 +3,7 @@ use bevy_rapier3d::prelude::*;
|
||||||
|
|
||||||
use crate::planet::PLANET_RADIUS;
|
use crate::planet::PLANET_RADIUS;
|
||||||
|
|
||||||
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015 + 90.0;
|
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.01;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct CyberBikeBody;
|
pub struct CyberBikeBody;
|
||||||
|
@ -14,9 +14,12 @@ pub struct CyberBikeCollider;
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct CyberBikeModel;
|
pub struct CyberBikeModel;
|
||||||
|
|
||||||
|
const BIKE_BODY_GROUP: InteractionGroups = InteractionGroups::new(0b01, 0b01);
|
||||||
|
const BIKE_WHEEL_GROUP: InteractionGroups = InteractionGroups::new(0b10, 0b10);
|
||||||
|
|
||||||
fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let xform = Transform::from_translation(Vec3::Y * SPAWN_ALTITUDE)
|
let xform = Transform::from_translation(Vec3::X * SPAWN_ALTITUDE)
|
||||||
.with_rotation(Quat::from_axis_angle(Vec3::X, -80.0f32.to_radians()));
|
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));
|
||||||
|
|
||||||
let mut bbody = RigidBodyBundle::default();
|
let mut bbody = RigidBodyBundle::default();
|
||||||
|
|
||||||
|
@ -42,7 +45,12 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
);
|
);
|
||||||
let bcollide = ColliderBundle {
|
let bcollide = ColliderBundle {
|
||||||
shape: shape.into(),
|
shape: shape.into(),
|
||||||
mass_properties: ColliderMassProps::Density(0.04).into(),
|
mass_properties: ColliderMassProps::Density(0.82).into(),
|
||||||
|
flags: ColliderFlags {
|
||||||
|
collision_groups: BIKE_BODY_GROUP,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
material: ColliderMaterial {
|
material: ColliderMaterial {
|
||||||
friction: 0.0,
|
friction: 0.0,
|
||||||
restitution: 0.0,
|
restitution: 0.0,
|
||||||
|
@ -73,18 +81,24 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
// seriously the cyberbike is so fucking huge what the heck
|
// seriously the cyberbike is so fucking huge what the heck
|
||||||
let wheel_positions = vec![-5.5, 4.7];
|
let wheel_positions = vec![-5.1, 4.7, 4.7, -5.1];
|
||||||
let wheel_rad = 0.7;
|
let wheel_rad = 1.55;
|
||||||
let wheel_y = -2.0;
|
let wheel_y = -1.5f32;
|
||||||
|
|
||||||
for wheel_z in wheel_positions {
|
for (i, &wheel_z) in wheel_positions.iter().enumerate() {
|
||||||
let offset = Vec3::new(0.0, wheel_y, wheel_z);
|
let wheel_x = if i % 2 == 0 { -2.5 } else { 2.5 };
|
||||||
|
let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
|
||||||
let trans = xform.translation + offset;
|
let trans = xform.translation + offset;
|
||||||
let wheel_pos_in_world = Isometry::from_parts(trans.into(), xform.rotation.into());
|
let wheel_pos_in_world = Isometry::from_parts(trans.into(), xform.rotation.into());
|
||||||
let _wheel_rb = commands
|
let _wheel_rb = commands
|
||||||
.spawn_bundle(RigidBodyBundle {
|
.spawn_bundle(RigidBodyBundle {
|
||||||
position: wheel_pos_in_world.into(),
|
position: wheel_pos_in_world.into(),
|
||||||
activation: RigidBodyActivation::cannot_sleep().into(),
|
activation: RigidBodyActivation::cannot_sleep().into(),
|
||||||
|
damping: RigidBodyDamping {
|
||||||
|
angular_damping: 0.8,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
ccd: RigidBodyCcd {
|
ccd: RigidBodyCcd {
|
||||||
ccd_enabled: true,
|
ccd_enabled: true,
|
||||||
ccd_max_dist: wheel_rad,
|
ccd_max_dist: wheel_rad,
|
||||||
|
@ -97,18 +111,23 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
.insert_bundle(ColliderBundle {
|
.insert_bundle(ColliderBundle {
|
||||||
material: ColliderMaterial::new(0.0, 0.0).into(),
|
material: ColliderMaterial::new(0.0, 0.0).into(),
|
||||||
shape: ColliderShape::ball(wheel_rad).into(),
|
shape: ColliderShape::ball(wheel_rad).into(),
|
||||||
mass_properties: ColliderMassProps::Density(0.01).into(),
|
mass_properties: ColliderMassProps::Density(0.001).into(),
|
||||||
|
flags: ColliderFlags {
|
||||||
|
collision_groups: BIKE_WHEEL_GROUP,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(ColliderPositionSync::Discrete)
|
.insert(ColliderPositionSync::Discrete)
|
||||||
.insert(ColliderDebugRender::from(Color::YELLOW))
|
.insert(ColliderDebugRender::from(Color::YELLOW))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let (stiffness, damping) = (0.1, 0.4);
|
let (stiffness, damping) = (0.011, 0.25);
|
||||||
|
|
||||||
let prismatic = PrismaticJoint::new(Vector::y_axis())
|
let prismatic = PrismaticJoint::new(Vector::y_axis())
|
||||||
.local_anchor1(offset.into())
|
.local_anchor1(offset.into())
|
||||||
.motor_position(-0.1, stiffness, damping);
|
.motor_position(-0.2, stiffness, damping);
|
||||||
|
|
||||||
commands.spawn_bundle(((JointBuilderComponent::new(prismatic, bike, _wheel_rb)),));
|
commands.spawn_bundle(((JointBuilderComponent::new(prismatic, bike, _wheel_rb)),));
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub struct CyberCamPlugin;
|
||||||
impl Plugin for CyberCamPlugin {
|
impl Plugin for CyberCamPlugin {
|
||||||
fn build(&self, app: &mut bevy::prelude::App) {
|
fn build(&self, app: &mut bevy::prelude::App) {
|
||||||
app.add_startup_system(setup_cybercams)
|
app.add_startup_system(setup_cybercams)
|
||||||
.add_state(CyberCameras::Debug)
|
.add_state(CyberCameras::Hero)
|
||||||
.add_system(cycle_cam_state)
|
.add_system(cycle_cam_state)
|
||||||
.add_system(update_active_camera)
|
.add_system(update_active_camera)
|
||||||
.add_system(follow_cyberbike);
|
.add_system(follow_cyberbike);
|
||||||
|
|
|
@ -12,9 +12,9 @@ use cyber_rider::{
|
||||||
};
|
};
|
||||||
|
|
||||||
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
|
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
|
||||||
sensitivity: 10.0, // steering
|
sensitivity: 60.0, // steering
|
||||||
accel: 30.0, // thrust
|
accel: 70.0, // thrust
|
||||||
gravity: 8.0,
|
gravity: 7.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in a new issue