merge wip rolling_wheels
This commit is contained in:
commit
ce6f6242c0
6 changed files with 79 additions and 98 deletions
|
@ -58,9 +58,9 @@ pub struct CatControllerSettings {
|
|||
impl Default for CatControllerSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
kp: 17.0,
|
||||
kd: 4.0,
|
||||
ki: 0.05,
|
||||
kp: 20.0,
|
||||
kd: 4.5,
|
||||
ki: 0.07,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ impl Default for CatControllerState {
|
|||
pitch_prev: Default::default(),
|
||||
decay_factor: 0.99,
|
||||
roll_limit: 1.5,
|
||||
pitch_limit: 1.2,
|
||||
pitch_limit: 1.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ impl Plugin for CyberActionPlugin {
|
|||
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_startup_system(zero_gravity)
|
||||
.add_system(surface_fix)
|
||||
.add_system(surface_fix.label("surface_fix"))
|
||||
.add_system(gravity.before("cat"))
|
||||
.add_system(falling_cat.label("cat"))
|
||||
.add_system(input_forces.label("iforces").after("cat"))
|
||||
|
|
|
@ -122,7 +122,7 @@ pub(super) fn surface_fix(
|
|||
cgroups.memberships = Group::NONE;
|
||||
cgroups.filters = Group::NONE;
|
||||
commands.entity(entity).insert(Tunneling {
|
||||
frames: 15,
|
||||
frames: 5,
|
||||
dir: -hit.1.normal,
|
||||
});
|
||||
}
|
||||
|
@ -140,6 +140,7 @@ pub(super) fn tunnel_out(
|
|||
),
|
||||
With<CyberWheel>,
|
||||
>,
|
||||
settings: Res<MovementSettings>,
|
||||
) {
|
||||
for (entity, mut tunneling, mut cgroups, mut force) in wheel_query.iter_mut() {
|
||||
if tunneling.frames == 0 {
|
||||
|
@ -149,7 +150,8 @@ pub(super) fn tunnel_out(
|
|||
continue;
|
||||
}
|
||||
tunneling.frames -= 1;
|
||||
force.force += tunneling.dir * tunneling.frames as f32;
|
||||
force.force += tunneling.dir * settings.gravity * 1.1;
|
||||
#[cfg(feature = "inspector")]
|
||||
dbg!(&tunneling);
|
||||
}
|
||||
}
|
||||
|
|
38
src/bike/components.rs
Normal file
38
src/bike/components.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use bevy::{
|
||||
prelude::{Component, ReflectResource, Resource},
|
||||
reflect::Reflect,
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CyberBikeBody;
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct CyberWheel;
|
||||
|
||||
#[derive(Resource, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct WheelConfig {
|
||||
pub front_forward: f32,
|
||||
pub front_stance: f32,
|
||||
pub rear_back: f32,
|
||||
pub y: f32,
|
||||
pub limits: [f32; 2],
|
||||
pub stiffness: f32,
|
||||
pub damping: f32,
|
||||
pub radius: f32,
|
||||
}
|
||||
|
||||
impl Default for WheelConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
front_forward: 0.9,
|
||||
front_stance: 0.65,
|
||||
rear_back: 1.1,
|
||||
y: -0.45,
|
||||
limits: [-0.7, 0.1],
|
||||
stiffness: 90.0,
|
||||
damping: 8.0,
|
||||
radius: 0.3,
|
||||
}
|
||||
}
|
||||
}
|
20
src/bike/mod.rs
Normal file
20
src/bike/mod.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
mod components;
|
||||
mod systems;
|
||||
|
||||
use bevy::prelude::{App, Plugin, StartupStage};
|
||||
use bevy_rapier3d::prelude::Group;
|
||||
|
||||
pub use self::components::*;
|
||||
use self::systems::spawn_cyberbike;
|
||||
|
||||
pub const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1);
|
||||
pub const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10);
|
||||
|
||||
pub struct CyberBikePlugin;
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,13 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use bevy::prelude::{shape::UVSphere as Tire, *};
|
||||
use bevy_rapier3d::{
|
||||
geometry::Group,
|
||||
prelude::{
|
||||
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
|
||||
MultibodyJoint, PrismaticJointBuilder, ReadMassProperties, Restitution, RigidBody,
|
||||
Sleeping, TransformInterpolation, Velocity,
|
||||
},
|
||||
use bevy_rapier3d::prelude::{
|
||||
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
|
||||
MultibodyJoint, PrismaticJointBuilder, ReadMassProperties, Restitution, RigidBody, Sleeping,
|
||||
TransformInterpolation, Velocity,
|
||||
};
|
||||
|
||||
use super::{
|
||||
CyberBikeBody, CyberWheel, WheelConfig, BIKE_BODY_COLLISION_GROUP, BIKE_WHEEL_COLLISION_GROUP,
|
||||
};
|
||||
use crate::{action::CatControllerState, planet::PLANET_RADIUS};
|
||||
|
||||
type Meshterial<'a> = (
|
||||
|
@ -17,44 +15,7 @@ type Meshterial<'a> = (
|
|||
ResMut<'a, Assets<StandardMaterial>>,
|
||||
);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CyberBikeBody;
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct CyberWheel;
|
||||
|
||||
#[derive(Resource, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct WheelConfig {
|
||||
pub front_forward: f32,
|
||||
pub front_stance: f32,
|
||||
pub rear_back: f32,
|
||||
pub y: f32,
|
||||
pub limits: [f32; 2],
|
||||
pub stiffness: f32,
|
||||
pub damping: f32,
|
||||
pub radius: f32,
|
||||
}
|
||||
|
||||
impl Default for WheelConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
front_forward: 0.9,
|
||||
front_stance: 0.65,
|
||||
rear_back: 1.1,
|
||||
y: -0.45,
|
||||
limits: [-0.7, 0.1],
|
||||
stiffness: 90.0,
|
||||
damping: 8.0,
|
||||
radius: 0.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1);
|
||||
pub const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10);
|
||||
|
||||
fn spawn_cyberbike(
|
||||
pub(super) fn spawn_cyberbike(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
wheel_conf: Res<WheelConfig>,
|
||||
|
@ -73,11 +34,6 @@ fn spawn_cyberbike(
|
|||
angular_damping: 2.0,
|
||||
linear_damping: 0.1,
|
||||
};
|
||||
let not_sleeping = Sleeping::disabled();
|
||||
let ccd = Ccd { enabled: true };
|
||||
|
||||
let bcollider_shape =
|
||||
Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.50);
|
||||
|
||||
let friction = Friction {
|
||||
coefficient: 0.0,
|
||||
|
@ -105,14 +61,14 @@ fn spawn_cyberbike(
|
|||
.spawn(RigidBody::Dynamic)
|
||||
.insert(spatialbundle)
|
||||
.insert((
|
||||
bcollider_shape,
|
||||
Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.50),
|
||||
bike_collision_group,
|
||||
mass_properties,
|
||||
damping,
|
||||
restitution,
|
||||
friction,
|
||||
not_sleeping,
|
||||
ccd,
|
||||
Sleeping::disabled(),
|
||||
Ccd { enabled: true },
|
||||
ReadMassProperties::default(),
|
||||
))
|
||||
.insert(TransformInterpolation {
|
||||
|
@ -134,24 +90,6 @@ 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>,
|
||||
mut meshterials: Meshterial,
|
||||
bquery: Query<(Entity, &Transform), With<CyberBikeBody>>,
|
||||
wheels: Query<Entity, With<CyberWheel>>,
|
||||
) {
|
||||
// we fuck with values in the egui inspector
|
||||
let (bike, xform) = bquery.single();
|
||||
if wheel_conf.is_changed() {
|
||||
for wheel in wheels.iter() {
|
||||
commands.entity(wheel).despawn_recursive();
|
||||
}
|
||||
spawn_tires(&mut commands, xform, bike, &wheel_conf, &mut meshterials);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_tires(
|
||||
commands: &mut Commands,
|
||||
xform: &Transform,
|
||||
|
@ -256,6 +194,7 @@ fn spawn_tires(
|
|||
wheels_collision_group,
|
||||
friction,
|
||||
CyberWheel,
|
||||
ExternalForce::default(),
|
||||
))
|
||||
.with_children(|wheel| {
|
||||
wheel.spawn(tire_spundle).insert(pbr_bundle.clone()).insert(
|
||||
|
@ -264,24 +203,6 @@ fn spawn_tires(
|
|||
end: None,
|
||||
},
|
||||
);
|
||||
})
|
||||
.insert(TransformInterpolation {
|
||||
start: None,
|
||||
end: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CyberBikePlugin;
|
||||
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);
|
||||
|
||||
#[cfg(feature = "inspector")]
|
||||
{
|
||||
app.add_system(re_tire);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue