better, wheels still get mired
This commit is contained in:
parent
66724e8946
commit
3b307f4389
11 changed files with 50 additions and 27 deletions
|
@ -36,7 +36,7 @@ impl Default for Tunneling {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Tunneling {
|
Tunneling {
|
||||||
frames: 15,
|
frames: 15,
|
||||||
dir: Vec3::ZERO,
|
dir: Vec3::Y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl Default for MovementSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
accel: 20.0,
|
accel: 20.0,
|
||||||
gravity: 4.8,
|
gravity: 9.8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ impl Plugin for CyberActionPlugin {
|
||||||
falling_cat,
|
falling_cat,
|
||||||
input_forces,
|
input_forces,
|
||||||
drag,
|
drag,
|
||||||
tunnel_out,
|
//tunnel_out,
|
||||||
surface_fix,
|
//surface_fix,
|
||||||
)
|
)
|
||||||
.chain(),
|
.chain(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||||
|
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
Commands, Entity, Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without,
|
Commands, Entity, Local, Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without,
|
||||||
};
|
};
|
||||||
use bevy_rapier3d::prelude::{
|
use bevy_rapier3d::prelude::{
|
||||||
CollisionGroups, ExternalForce, Group, MultibodyJoint, QueryFilter, RapierConfiguration,
|
CollisionGroups, ExternalForce, Group, MultibodyJoint, QueryFilter, RapierConfiguration,
|
||||||
|
@ -94,13 +94,19 @@ pub(super) fn cyber_lean(
|
||||||
|
|
||||||
/// PID-based controller for stabilizing attitude; keeps the cyberbike upright.
|
/// PID-based controller for stabilizing attitude; keeps the cyberbike upright.
|
||||||
pub(super) fn falling_cat(
|
pub(super) fn falling_cat(
|
||||||
mut bike_query: Query<(&Transform, &mut ExternalForce, &mut CatControllerState)>,
|
mut bike_query: Query<(
|
||||||
|
&Transform,
|
||||||
|
&Velocity,
|
||||||
|
&mut ExternalForce,
|
||||||
|
&mut CatControllerState,
|
||||||
|
)>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
settings: Res<CatControllerSettings>,
|
settings: Res<CatControllerSettings>,
|
||||||
lean: Res<CyberLean>,
|
lean: Res<CyberLean>,
|
||||||
|
mut count: Local<usize>,
|
||||||
) {
|
) {
|
||||||
let (xform, mut forces, mut control_vars) = bike_query.single_mut();
|
let (xform, vel, mut forces, mut control_vars) = bike_query.single_mut();
|
||||||
let world_up = xform.translation.normalize();
|
let world_up = Vec3::Y; //xform.translation.normalize();
|
||||||
let rot = Quat::from_axis_angle(*xform.back(), lean.lean);
|
let rot = Quat::from_axis_angle(*xform.back(), lean.lean);
|
||||||
let target_up = rotate_point(&world_up, &rot).normalize();
|
let target_up = rotate_point(&world_up, &rot).normalize();
|
||||||
|
|
||||||
|
@ -109,6 +115,16 @@ pub(super) fn falling_cat(
|
||||||
let roll_error = bike_right.dot(target_up);
|
let roll_error = bike_right.dot(target_up);
|
||||||
let pitch_error = world_up.dot(*xform.back());
|
let pitch_error = world_up.dot(*xform.back());
|
||||||
|
|
||||||
|
if *count < 30 {
|
||||||
|
if *count == 0 {
|
||||||
|
dbg!(&xform.translation);
|
||||||
|
dbg!(&vel.linvel);
|
||||||
|
}
|
||||||
|
*count += 1;
|
||||||
|
} else {
|
||||||
|
*count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// only try to correct roll if we're not totally vertical
|
// only try to correct roll if we're not totally vertical
|
||||||
if pitch_error.abs() < 0.95 {
|
if pitch_error.abs() < 0.95 {
|
||||||
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds());
|
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds());
|
||||||
|
@ -186,18 +202,18 @@ pub(super) fn surface_fix(
|
||||||
|
|
||||||
for (entity, xform, mut cgroups) in wheel_query.iter_mut() {
|
for (entity, xform, mut cgroups) in wheel_query.iter_mut() {
|
||||||
//let ray_dir = xform.translation.normalize();
|
//let ray_dir = xform.translation.normalize();
|
||||||
let ray_dir = xform.right().cross(span).normalize();
|
let ray_dir = Vec3::NEG_Y; //xform.right().cross(span).normalize();
|
||||||
if let Some(hit) = context.cast_ray_and_get_normal(
|
if let Some(hit) = context.cast_ray_and_get_normal(
|
||||||
xform.translation,
|
xform.translation,
|
||||||
ray_dir,
|
ray_dir,
|
||||||
config.radius * 1.1,
|
config.radius,
|
||||||
false,
|
false,
|
||||||
QueryFilter::only_fixed(),
|
QueryFilter::only_fixed(),
|
||||||
) {
|
) {
|
||||||
cgroups.memberships = Group::NONE;
|
//cgroups.memberships = Group::NONE;
|
||||||
cgroups.filters = Group::NONE;
|
//cgroups.filters = Group::NONE;
|
||||||
commands.entity(entity).insert(Tunneling {
|
commands.entity(entity).insert(Tunneling {
|
||||||
frames: 3,
|
frames: 2,
|
||||||
dir: hit.1.normal,
|
dir: hit.1.normal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -227,7 +243,7 @@ pub(super) fn tunnel_out(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tunneling.frames -= 1;
|
tunneling.frames -= 1;
|
||||||
force.force = tunneling.dir * settings.gravity * 1.5 * mprops.get().mass;
|
force.force = tunneling.dir * settings.gravity * 1.1 * mprops.get().mass;
|
||||||
#[cfg(feature = "inspector")]
|
#[cfg(feature = "inspector")]
|
||||||
dbg!(&tunneling);
|
dbg!(&tunneling);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub(super) fn spawn_cyberbike(
|
||||||
wheel_conf: Res<WheelConfig>,
|
wheel_conf: Res<WheelConfig>,
|
||||||
mut meshterials: Meshterial,
|
mut meshterials: Meshterial,
|
||||||
) {
|
) {
|
||||||
let altitude = 53.0;
|
let altitude = 3.0;
|
||||||
|
|
||||||
let mut xform = Transform::from_translation(Vec3::Y * altitude);
|
let mut xform = Transform::from_translation(Vec3::Y * altitude);
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,9 @@ impl Default for WheelConfig {
|
||||||
rear_back: 1.0,
|
rear_back: 1.0,
|
||||||
y: -0.1,
|
y: -0.1,
|
||||||
limits: [-0.5, 0.1],
|
limits: [-0.5, 0.1],
|
||||||
stiffness: 190.0,
|
stiffness: 30.0,
|
||||||
damping: 8.0,
|
damping: 8.0,
|
||||||
radius: 0.25,
|
radius: 0.35,
|
||||||
thickness: 0.11,
|
thickness: 0.11,
|
||||||
friction: 1.2,
|
friction: 1.2,
|
||||||
restitution: 0.95,
|
restitution: 0.95,
|
||||||
|
|
|
@ -51,9 +51,9 @@ pub fn spawn_wheels(
|
||||||
|
|
||||||
let material = StandardMaterial {
|
let material = StandardMaterial {
|
||||||
base_color: Color::Rgba {
|
base_color: Color::Rgba {
|
||||||
red: 0.01,
|
red: 0.99,
|
||||||
green: 0.01,
|
green: 0.99,
|
||||||
blue: 0.01,
|
blue: 0.05,
|
||||||
alpha: 1.0,
|
alpha: 1.0,
|
||||||
},
|
},
|
||||||
alpha_mode: AlphaMode::Opaque,
|
alpha_mode: AlphaMode::Opaque,
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn follow_cyberbike(
|
||||||
offset: Res<DebugCamOffset>,
|
offset: Res<DebugCamOffset>,
|
||||||
) {
|
) {
|
||||||
let bike_xform = *query.p0().single();
|
let bike_xform = *query.p0().single();
|
||||||
let up = bike_xform.translation.normalize();
|
let up = Vec3::Y; //bike_xform.translation.normalize();
|
||||||
|
|
||||||
for (mut cam_xform, cam_type) in query.p1().iter_mut() {
|
for (mut cam_xform, cam_type) in query.p1().iter_mut() {
|
||||||
match *cam_type {
|
match *cam_type {
|
||||||
|
|
|
@ -19,6 +19,7 @@ impl Plugin for CyberGlamorPlugin {
|
||||||
let mode = DebugRenderMode::CONTACTS
|
let mode = DebugRenderMode::CONTACTS
|
||||||
| DebugRenderMode::SOLVER_CONTACTS
|
| DebugRenderMode::SOLVER_CONTACTS
|
||||||
| DebugRenderMode::JOINTS
|
| DebugRenderMode::JOINTS
|
||||||
|
| DebugRenderMode::COLLIDER_SHAPES
|
||||||
| DebugRenderMode::RIGID_BODY_AXES;
|
| DebugRenderMode::RIGID_BODY_AXES;
|
||||||
|
|
||||||
let rplugin = RapierDebugRenderPlugin {
|
let rplugin = RapierDebugRenderPlugin {
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn spawn_static_lights(
|
||||||
|
|
||||||
commands.insert_resource(AmbientLight {
|
commands.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 1.0,
|
brightness: 100.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
// let _cascade_shadow_config = CascadeShadowConfigBuilder {
|
// let _cascade_shadow_config = CascadeShadowConfigBuilder {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
#[cfg(feature = "inspector")]
|
//#[cfg(feature = "inspector")]
|
||||||
use cyber_rider::glamor::CyberGlamorPlugin;
|
use cyber_rider::glamor::CyberGlamorPlugin;
|
||||||
use cyber_rider::{
|
use cyber_rider::{
|
||||||
action::CyberActionPlugin, bike::CyberBikePlugin, camera::CyberCamPlugin, disable_mouse_trap,
|
action::CyberActionPlugin, bike::CyberBikePlugin, camera::CyberCamPlugin, disable_mouse_trap,
|
||||||
|
@ -33,7 +33,7 @@ fn main() {
|
||||||
.add_systems(Startup, disable_mouse_trap)
|
.add_systems(Startup, disable_mouse_trap)
|
||||||
.add_systems(Update, bevy::window::close_on_esc);
|
.add_systems(Update, bevy::window::close_on_esc);
|
||||||
|
|
||||||
#[cfg(feature = "inspector")]
|
//#[cfg(feature = "inspector")]
|
||||||
app.add_plugins(CyberGlamorPlugin);
|
app.add_plugins(CyberGlamorPlugin);
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
|
|
|
@ -24,7 +24,11 @@ fn spawn_planet(
|
||||||
|
|
||||||
let (mesh, shape) = gen_planet(999.9);
|
let (mesh, shape) = gen_planet(999.9);
|
||||||
|
|
||||||
let pbody = (RigidBody::Fixed, Ccd { enabled: true });
|
let pbody = (
|
||||||
|
RigidBody::Fixed,
|
||||||
|
Ccd { enabled: true },
|
||||||
|
Transform::from_xyz(0.0, 0.1, 0.0),
|
||||||
|
);
|
||||||
|
|
||||||
let pcollide = (
|
let pcollide = (
|
||||||
shape,
|
shape,
|
||||||
|
@ -33,6 +37,7 @@ fn spawn_planet(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Restitution::new(0.8),
|
Restitution::new(0.8),
|
||||||
|
Transform::from_xyz(0.0, 0.1, 0.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
commands
|
commands
|
||||||
|
@ -42,6 +47,7 @@ fn spawn_planet(
|
||||||
base_color: Color::GREEN,
|
base_color: Color::GREEN,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
transform: Transform::from_xyz(0.0, 0.1, 0.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(pbody)
|
.insert(pbody)
|
||||||
|
@ -61,9 +67,9 @@ impl Plugin for CyberPlanetPlugin {
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
fn gen_planet(span: f32) -> (Mesh, Collider) {
|
fn gen_planet(span: f32) -> (Mesh, Collider) {
|
||||||
let mesh = Cuboid::new(span, 50.0, span);
|
let mesh = Cuboid::new(span, 0.1, span);
|
||||||
|
|
||||||
let collider = Collider::cuboid(span, 50.0, span);
|
let collider = Collider::cuboid(span / 2.0, 0.05, span / 2.0);
|
||||||
|
|
||||||
(mesh.mesh(), collider)
|
(mesh.mesh(), collider)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue