Compare commits
4 commits
3d0d86f24c
...
6b9a879927
Author | SHA1 | Date | |
---|---|---|---|
|
6b9a879927 | ||
|
3f965652d1 | ||
|
5cfc2f7033 | ||
|
9cb53bfa2e |
11 changed files with 121 additions and 172 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -284,9 +284,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "avian3d"
|
name = "avian3d"
|
||||||
version = "0.1.1"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "54325576b6efa46576db611624db749b553d0c66e439862bdc60c43e01f012f9"
|
checksum = "0a8da53296a1bc166b84f99aa7c6b9d8c10c71f0c022bc4fc72dd1fc49323b29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"avian_derive",
|
"avian_derive",
|
||||||
"bevy",
|
"bevy",
|
||||||
|
@ -1223,9 +1223,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake3"
|
name = "blake3"
|
||||||
version = "1.5.3"
|
version = "1.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210"
|
checksum = "3d08263faac5cde2a4d52b513dadb80846023aade56fcd8fc99ba73ba8050e92"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
@ -1296,9 +1296,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.6.1"
|
version = "1.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952"
|
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "calloop"
|
name = "calloop"
|
||||||
|
@ -1316,12 +1316,13 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.1.5"
|
version = "1.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
|
checksum = "47de7e88bbbd467951ae7f5a6f34f70d1b4d9cfce53d5fd70f74ebe118b3db56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3066,7 +3067,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall 0.5.3",
|
"redox_syscall 0.5.2",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
@ -3366,9 +3367,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.3"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
|
checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::{Component, ReflectResource, Resource},
|
prelude::{Component, ReflectResource, Resource, Vec3},
|
||||||
reflect::Reflect,
|
reflect::Reflect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +26,21 @@ impl ActionDebugInstant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Component)]
|
||||||
|
pub(super) struct Tunneling {
|
||||||
|
pub frames: usize,
|
||||||
|
pub dir: Vec3,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Tunneling {
|
||||||
|
fn default() -> Self {
|
||||||
|
Tunneling {
|
||||||
|
frames: 15,
|
||||||
|
dir: Vec3::ZERO,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Resource, Reflect)]
|
#[derive(Debug, Resource, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct MovementSettings {
|
pub struct MovementSettings {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use avian3d::prelude::{PhysicsPlugins, SubstepCount};
|
use avian3d::prelude::*;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::Update,
|
app::{Startup, Update},
|
||||||
diagnostic::FrameTimeDiagnosticsPlugin,
|
diagnostic::FrameTimeDiagnosticsPlugin,
|
||||||
ecs::reflect::ReflectResource,
|
ecs::reflect::ReflectResource,
|
||||||
prelude::{App, IntoSystemConfigs, Plugin, Resource},
|
prelude::{App, IntoSystemConfigs, Plugin, Resource},
|
||||||
|
@ -29,14 +29,14 @@ impl Plugin for CyberActionPlugin {
|
||||||
.init_resource::<CyberLean>()
|
.init_resource::<CyberLean>()
|
||||||
.register_type::<CyberLean>()
|
.register_type::<CyberLean>()
|
||||||
.register_type::<CatControllerSettings>()
|
.register_type::<CatControllerSettings>()
|
||||||
.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin))
|
.add_plugins((
|
||||||
|
PhysicsPlugins::default(),
|
||||||
|
FrameTimeDiagnosticsPlugin::default(),
|
||||||
|
))
|
||||||
.insert_resource(SubstepCount(12))
|
.insert_resource(SubstepCount(12))
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(gravity, cyber_lean, falling_cat, input_forces).chain(),
|
||||||
gravity,
|
|
||||||
(cyber_lean, suspension, falling_cat, input_forces).after(clear_forces),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||||
|
|
||||||
use avian3d::{
|
use avian3d::{
|
||||||
dynamics::solver::xpbd::AngularConstraint,
|
dynamics::solver::xpbd::AngularConstraint, parry::mass_properties::MassProperties, prelude::*,
|
||||||
prelude::{
|
};
|
||||||
ColliderMassProperties, ExternalForce, ExternalTorque, Gravity, LinearVelocity,
|
use bevy::prelude::{
|
||||||
PrismaticJoint, RigidBodyQuery,
|
Commands, Entity, Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without};
|
|
||||||
|
|
||||||
use super::{CatControllerSettings, CatControllerState, CyberLean, MovementSettings};
|
//#[cfg(feature = "inspector")]
|
||||||
|
//use super::ActionDebugInstant;
|
||||||
|
use super::{CatControllerSettings, CatControllerState, CyberLean, MovementSettings, Tunneling};
|
||||||
use crate::{
|
use crate::{
|
||||||
bike::{CyberBikeBody, CyberFork, CyberSpring, CyberSteering, CyberWheel, WheelConfig},
|
bike::{CyberBikeBody, CyberSteering, CyberWheel, WheelConfig, BIKE_WHEEL_COLLISION_GROUP},
|
||||||
input::InputState,
|
input::InputState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,42 +37,14 @@ fn rotate_point(pt: &Vec3, rot: &Quat) -> Vec3 {
|
||||||
|
|
||||||
/// The gravity vector points from the cyberbike to the center of the planet.
|
/// The gravity vector points from the cyberbike to the center of the planet.
|
||||||
pub(super) fn gravity(
|
pub(super) fn gravity(
|
||||||
xform: Query<&Transform, With<CyberBikeBody>>,
|
mut query: Query<(&Transform, &mut ExternalForce), With<CyberBikeBody>>,
|
||||||
|
|
||||||
settings: Res<MovementSettings>,
|
settings: Res<MovementSettings>,
|
||||||
mut gravity: ResMut<Gravity>,
|
mut gravity: ResMut<Gravity>,
|
||||||
|
#[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>,
|
||||||
) {
|
) {
|
||||||
let xform = xform.single();
|
let (xform, mut forces) = query.single_mut();
|
||||||
*gravity = Gravity(xform.translation.normalize() * -settings.gravity);
|
*gravity = Gravity(xform.translation.normalize() * -settings.gravity);
|
||||||
|
forces.clear();
|
||||||
// clear all external forces
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn clear_forces(mut forces: Query<(&mut ExternalForce, &mut ExternalTorque)>) {
|
|
||||||
for (mut force, mut torque) in forces.iter_mut() {
|
|
||||||
force.clear();
|
|
||||||
torque.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn suspension(
|
|
||||||
movment_settings: Res<MovementSettings>,
|
|
||||||
wheel_config: Res<WheelConfig>,
|
|
||||||
mass: Query<&ColliderMassProperties, With<CyberBikeBody>>,
|
|
||||||
mut axels: Query<(&mut ExternalForce, &CyberSpring, &Transform)>,
|
|
||||||
) {
|
|
||||||
let mass = if let Ok(mass) = mass.get_single() {
|
|
||||||
mass.mass.0
|
|
||||||
} else {
|
|
||||||
1.0
|
|
||||||
};
|
|
||||||
let gravity = movment_settings.gravity;
|
|
||||||
let mag = -wheel_config.stiffness * mass * gravity;
|
|
||||||
for (mut force, spring, xform) in axels.iter_mut() {
|
|
||||||
let spring = mag * spring.0;
|
|
||||||
let spring = xform.translation + spring;
|
|
||||||
let _ = force.apply_force(spring);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The desired lean angle, given steering input and speed.
|
/// The desired lean angle, given steering input and speed.
|
||||||
|
@ -134,30 +106,26 @@ pub(super) fn input_forces(
|
||||||
settings: Res<MovementSettings>,
|
settings: Res<MovementSettings>,
|
||||||
input: Res<InputState>,
|
input: Res<InputState>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
fork: Query<&PrismaticJoint, With<CyberFork>>,
|
axle: Query<Entity, With<CyberSteering>>,
|
||||||
mut axle: Query<(RigidBodyQuery, &Transform), With<CyberSteering>>,
|
|
||||||
mut braking_query: Query<&mut ExternalTorque, With<CyberWheel>>,
|
mut braking_query: Query<&mut ExternalTorque, With<CyberWheel>>,
|
||||||
mut body_query: Query<
|
mut body_query: Query<
|
||||||
(
|
(
|
||||||
RigidBodyQuery,
|
Entity,
|
||||||
&Transform,
|
&Transform,
|
||||||
&ColliderMassProperties,
|
&ColliderMassProperties,
|
||||||
&mut ExternalForce,
|
&mut ExternalForce,
|
||||||
),
|
),
|
||||||
(With<CyberBikeBody>, Without<CyberSteering>),
|
With<CyberBikeBody>,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
let Ok((mut bike, xform, mass, mut forces)) = body_query.get_single_mut() else {
|
let (bike, xform, mass, mut forces) = body_query.single_mut();
|
||||||
bevy::log::warn!("no bike body found");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let dt = time.delta_seconds();
|
let dt = time.delta_seconds();
|
||||||
|
|
||||||
// thrust
|
// thrust
|
||||||
let thrust = xform.forward() * input.throttle * settings.accel;
|
let thrust = xform.forward() * input.throttle * settings.accel;
|
||||||
let point = xform.translation + *xform.back();
|
let point = xform.translation + *xform.back();
|
||||||
|
|
||||||
let _ = *forces.apply_force_at_point(dt * thrust, point, mass.center_of_mass.0);
|
*forces.apply_force_at_point(dt * thrust, point, mass.center_of_mass.0);
|
||||||
|
|
||||||
// brake + thrust
|
// brake + thrust
|
||||||
for mut motor in braking_query.iter_mut() {
|
for mut motor in braking_query.iter_mut() {
|
||||||
|
@ -174,14 +142,7 @@ pub(super) fn input_forces(
|
||||||
|
|
||||||
// steering
|
// steering
|
||||||
let _angle = yaw_to_angle(input.yaw);
|
let _angle = yaw_to_angle(input.yaw);
|
||||||
let (mut axle, xform) = axle.single_mut();
|
let _axle = axle.single();
|
||||||
|
//steering.align_orientation(bike, steering, rotation_difference, lagrange,
|
||||||
let cur_rot = xform.rotation;
|
// compliance, dt)
|
||||||
let fork = fork.single();
|
|
||||||
let axis = fork.free_axis.normalize();
|
|
||||||
let new = Quat::from_axis_angle(axis, _angle);
|
|
||||||
let diff = (new - cur_rot).to_scaled_axis();
|
|
||||||
let mut compliance = 1.0;
|
|
||||||
|
|
||||||
fork.align_orientation(&mut axle, &mut bike, diff, &mut compliance, 1.0, dt);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,20 +37,24 @@ pub(super) fn spawn_cyberbike(
|
||||||
|
|
||||||
let scene = asset_server.load("cb-no-y_up.glb#Scene0");
|
let scene = asset_server.load("cb-no-y_up.glb#Scene0");
|
||||||
|
|
||||||
let body_collider =
|
let spatialbundle = SpatialBundle {
|
||||||
|
transform: xform,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let body =
|
||||||
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
|
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
|
||||||
|
let mass_props = MassPropertiesBundle::new_computed(&body, 0.6);
|
||||||
let bike = commands
|
let bike = commands
|
||||||
.spawn(SpatialBundle::from_transform(xform))
|
.spawn(RigidBody::Dynamic)
|
||||||
|
.insert(spatialbundle)
|
||||||
.insert((
|
.insert((
|
||||||
RigidBody::Dynamic,
|
body,
|
||||||
body_collider,
|
mass_props.clone(),
|
||||||
bike_collision_group,
|
bike_collision_group,
|
||||||
restitution,
|
restitution,
|
||||||
friction,
|
friction,
|
||||||
SleepingDisabled,
|
SleepingDisabled,
|
||||||
CyberBikeBody,
|
|
||||||
CatControllerState::default(),
|
|
||||||
ColliderDensity(0.6),
|
|
||||||
LinearDamping(0.1),
|
LinearDamping(0.1),
|
||||||
AngularDamping(2.0),
|
AngularDamping(2.0),
|
||||||
LinearVelocity::ZERO,
|
LinearVelocity::ZERO,
|
||||||
|
@ -64,6 +68,8 @@ pub(super) fn spawn_cyberbike(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.insert(CyberBikeBody)
|
||||||
|
.insert(CatControllerState::default())
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
spawn_wheels(&mut commands, bike, &wheel_conf, &mut meshterials);
|
spawn_wheels(&mut commands, bike, &wheel_conf, &mut meshterials);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
math::Vec3,
|
|
||||||
prelude::{Component, ReflectResource, Resource},
|
prelude::{Component, ReflectResource, Resource},
|
||||||
reflect::Reflect,
|
reflect::Reflect,
|
||||||
};
|
};
|
||||||
|
@ -7,18 +6,12 @@ use bevy::{
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct CyberBikeBody;
|
pub struct CyberBikeBody;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Component)]
|
#[derive(Clone, Component)]
|
||||||
pub struct CyberSteering;
|
pub struct CyberSteering;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Component)]
|
#[derive(Clone, Debug, Component)]
|
||||||
pub struct CyberWheel;
|
pub struct CyberWheel;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Component)]
|
|
||||||
pub struct CyberSpring(pub Vec3);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Component)]
|
|
||||||
pub struct CyberFork;
|
|
||||||
|
|
||||||
#[derive(Resource, Reflect)]
|
#[derive(Resource, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct WheelConfig {
|
pub struct WheelConfig {
|
||||||
|
@ -42,7 +35,7 @@ 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: 3.0,
|
stiffness: 190.0,
|
||||||
damping: 8.0,
|
damping: 8.0,
|
||||||
radius: 0.25,
|
radius: 0.25,
|
||||||
thickness: 0.11,
|
thickness: 0.11,
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod components;
|
||||||
mod wheels;
|
mod wheels;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{PostStartup, Startup},
|
app::PostStartup,
|
||||||
prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial},
|
prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@ 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_systems(Startup, spawn_cyberbike);
|
.add_systems(PostStartup, spawn_cyberbike);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::prelude::{Torus as Tire, *};
|
use bevy::prelude::{Torus as Tire, *};
|
||||||
|
|
||||||
use super::{
|
use super::{CyberSteering, CyberWheel, Meshterial, WheelConfig, BIKE_WHEEL_COLLISION_GROUP};
|
||||||
CyberFork, CyberSpring, CyberSteering, CyberWheel, Meshterial, WheelConfig,
|
|
||||||
BIKE_WHEEL_COLLISION_GROUP,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn spawn_wheels(
|
pub fn spawn_wheels(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
@ -15,6 +12,7 @@ pub fn spawn_wheels(
|
||||||
let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP;
|
let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP;
|
||||||
let wheels_collision_group = CollisionLayers::new(membership, filter);
|
let wheels_collision_group = CollisionLayers::new(membership, filter);
|
||||||
let wheel_y = conf.y;
|
let wheel_y = conf.y;
|
||||||
|
let stiffness = conf.stiffness;
|
||||||
let not_sleeping = SleepingDisabled;
|
let not_sleeping = SleepingDisabled;
|
||||||
let ccd = SweptCcd::NON_LINEAR.include_dynamic(false);
|
let ccd = SweptCcd::NON_LINEAR.include_dynamic(false);
|
||||||
let limits = conf.limits;
|
let limits = conf.limits;
|
||||||
|
@ -86,26 +84,11 @@ pub fn spawn_wheels(
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let spring = CyberSpring(suspension_axis);
|
let axel = if let Some(ref steering) = steering {
|
||||||
let axel = if let Some(steering) = steering {
|
commands.spawn((RigidBody::Dynamic, ExternalForce::ZERO, steering.clone()))
|
||||||
commands.spawn((
|
|
||||||
RigidBody::Dynamic,
|
|
||||||
ExternalForce::ZERO,
|
|
||||||
steering,
|
|
||||||
spring,
|
|
||||||
Collider::sphere(0.1),
|
|
||||||
ColliderDensity(0.1),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
commands.spawn((
|
commands.spawn((RigidBody::Dynamic, ExternalForce::ZERO))
|
||||||
RigidBody::Dynamic,
|
|
||||||
ExternalForce::ZERO,
|
|
||||||
spring,
|
|
||||||
Collider::sphere(0.1),
|
|
||||||
ColliderDensity(0.1),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
.insert(SpatialBundle::default())
|
|
||||||
.id();
|
.id();
|
||||||
let axel_joint = RevoluteJoint::new(axel, wheel).with_aligned_axis(Vec3::NEG_X);
|
let axel_joint = RevoluteJoint::new(axel, wheel).with_aligned_axis(Vec3::NEG_X);
|
||||||
commands.spawn(axel_joint);
|
commands.spawn(axel_joint);
|
||||||
|
@ -117,7 +100,7 @@ pub fn spawn_wheels(
|
||||||
.with_local_anchor_1(Vec3::new(0.0, 0.0, 0.1))
|
.with_local_anchor_1(Vec3::new(0.0, 0.0, 0.1))
|
||||||
.with_local_anchor_2(offset)
|
.with_local_anchor_2(offset)
|
||||||
.with_limits(limits[0], limits[1]);
|
.with_limits(limits[0], limits[1]);
|
||||||
commands.spawn((joint, CyberFork));
|
commands.spawn(joint);
|
||||||
} else {
|
} else {
|
||||||
let joint = PrismaticJoint::new(axel, bike)
|
let joint = PrismaticJoint::new(axel, bike)
|
||||||
.with_free_axis(suspension_axis)
|
.with_free_axis(suspension_axis)
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn follow_cyberbike(
|
||||||
// handle input pitch
|
// handle input pitch
|
||||||
let angle = input.pitch.powi(3) * MAX_PITCH;
|
let angle = input.pitch.powi(3) * MAX_PITCH;
|
||||||
let axis = cam_xform.right();
|
let axis = cam_xform.right();
|
||||||
cam_xform.rotate(Quat::from_axis_angle(*axis, angle));
|
cam_xform.rotate(Quat::from_axis_angle(axis, angle));
|
||||||
}
|
}
|
||||||
CyberCameras::Debug => {
|
CyberCameras::Debug => {
|
||||||
let mut ncx = bike_xform.to_owned();
|
let mut ncx = bike_xform.to_owned();
|
||||||
|
@ -101,7 +101,7 @@ fn update_active_camera(
|
||||||
) {
|
) {
|
||||||
// find the camera with the current state, set it as the ActiveCamera
|
// find the camera with the current state, set it as the ActiveCamera
|
||||||
query.iter_mut().for_each(|(mut cam, cyber)| {
|
query.iter_mut().for_each(|(mut cam, cyber)| {
|
||||||
if cyber.eq(&state.get()) {
|
if cyber.eq(&state.0) {
|
||||||
cam.is_active = true;
|
cam.is_active = true;
|
||||||
} else {
|
} else {
|
||||||
cam.is_active = false;
|
cam.is_active = false;
|
||||||
|
@ -112,13 +112,13 @@ fn update_active_camera(
|
||||||
fn cycle_cam_state(
|
fn cycle_cam_state(
|
||||||
state: Res<State<CyberCameras>>,
|
state: Res<State<CyberCameras>>,
|
||||||
mut next: ResMut<NextState<CyberCameras>>,
|
mut next: ResMut<NextState<CyberCameras>>,
|
||||||
mut keys: ResMut<ButtonInput<KeyCode>>,
|
mut keys: ResMut<Input<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if keys.just_pressed(KeyCode::KeyD) {
|
if keys.just_pressed(KeyCode::D) {
|
||||||
let new_state = state.get().next();
|
let new_state = state.0.next();
|
||||||
info!("{:?}", new_state);
|
info!("{:?}", new_state);
|
||||||
next.set(new_state);
|
next.set(new_state);
|
||||||
keys.reset(KeyCode::KeyD);
|
keys.reset(KeyCode::D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +132,9 @@ impl Plugin for CyberCamPlugin {
|
||||||
|
|
||||||
fn common(app: &mut bevy::prelude::App) {
|
fn common(app: &mut bevy::prelude::App) {
|
||||||
app.insert_resource(DebugCamOffset::default())
|
app.insert_resource(DebugCamOffset::default())
|
||||||
.add_systems(Startup, setup_cybercams)
|
.add_startup_system(setup_cybercams)
|
||||||
.init_state::<CyberCameras>()
|
.add_state::<CyberCameras>()
|
||||||
.add_systems(
|
.add_system(cycle_cam_state)
|
||||||
Update,
|
.add_system(update_active_camera)
|
||||||
(cycle_cam_state, update_active_camera, follow_cyberbike),
|
.add_system(follow_cyberbike);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@ use crate::planet::PLANET_RADIUS;
|
||||||
|
|
||||||
pub const LIGHT_RANGE: f32 = 90.0;
|
pub const LIGHT_RANGE: f32 = 90.0;
|
||||||
|
|
||||||
static BLUE: Color = Color::linear_rgb(0.0, 0.0, 1.0);
|
|
||||||
static PINK: Color = Color::linear_rgb(199.0 / 255.0, 21.0 / 255.0, 113.0 / 255.0);
|
|
||||||
|
|
||||||
fn spawn_static_lights(
|
fn spawn_static_lights(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
@ -15,7 +12,7 @@ fn spawn_static_lights(
|
||||||
let pink_light = PointLight {
|
let pink_light = PointLight {
|
||||||
intensity: 1_00.0,
|
intensity: 1_00.0,
|
||||||
range: LIGHT_RANGE,
|
range: LIGHT_RANGE,
|
||||||
color: PINK,
|
color: Color::PINK,
|
||||||
radius: 1.0,
|
radius: 1.0,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -24,7 +21,7 @@ fn spawn_static_lights(
|
||||||
let blue_light = PointLight {
|
let blue_light = PointLight {
|
||||||
intensity: 1_000.0,
|
intensity: 1_000.0,
|
||||||
range: LIGHT_RANGE,
|
range: LIGHT_RANGE,
|
||||||
color: BLUE,
|
color: Color::BLUE,
|
||||||
radius: 1.0,
|
radius: 1.0,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -51,10 +48,16 @@ fn spawn_static_lights(
|
||||||
})
|
})
|
||||||
.with_children(|builder| {
|
.with_children(|builder| {
|
||||||
builder.spawn(PbrBundle {
|
builder.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(Sphere::new(10.0))),
|
mesh: meshes.add(
|
||||||
|
Mesh::try_from(shape::Icosphere {
|
||||||
|
radius: 10.0,
|
||||||
|
subdivisions: 2,
|
||||||
|
})
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: BLUE,
|
base_color: Color::BLUE,
|
||||||
emissive: PINK.into(),
|
emissive: Color::PINK,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -69,10 +72,16 @@ fn spawn_static_lights(
|
||||||
})
|
})
|
||||||
.with_children(|builder| {
|
.with_children(|builder| {
|
||||||
builder.spawn(PbrBundle {
|
builder.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(Sphere::new(10.0))),
|
mesh: meshes.add(
|
||||||
|
Mesh::try_from(shape::Icosphere {
|
||||||
|
radius: 10.0,
|
||||||
|
subdivisions: 2,
|
||||||
|
})
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: PINK,
|
base_color: Color::PINK,
|
||||||
emissive: BLUE.into(),
|
emissive: Color::BLUE,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -83,6 +92,6 @@ fn spawn_static_lights(
|
||||||
pub struct CyberSpaceLightsPlugin;
|
pub struct CyberSpaceLightsPlugin;
|
||||||
impl Plugin for CyberSpaceLightsPlugin {
|
impl Plugin for CyberSpaceLightsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, spawn_static_lights);
|
app.add_startup_system(spawn_static_lights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -8,7 +8,7 @@ use cyber_rider::{
|
||||||
};
|
};
|
||||||
|
|
||||||
//const CYBER_SKY: Color = Color::rgb(0.07, 0.001, 0.02);
|
//const CYBER_SKY: Color = Color::rgb(0.07, 0.001, 0.02);
|
||||||
const CYBER_SKY: Color = Color::srgb(0.64, 0.745, 0.937); // a light blue sky
|
const CYBER_SKY: Color = Color::rgb(0.64, 0.745, 0.937); // a light blue sky
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
@ -21,36 +21,18 @@ fn main() {
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}))
|
}))
|
||||||
.add_plugins((
|
.add_plugin(CyberPlanetPlugin)
|
||||||
CyberPlanetPlugin,
|
.add_plugin(CyberInputPlugin)
|
||||||
CyberInputPlugin,
|
.add_plugin(CyberActionPlugin)
|
||||||
CyberActionPlugin,
|
.add_plugin(CyberCamPlugin)
|
||||||
CyberCamPlugin,
|
.add_plugin(CyberSpaceLightsPlugin)
|
||||||
CyberSpaceLightsPlugin,
|
.add_plugin(CyberUIPlugin)
|
||||||
CyberUIPlugin,
|
.add_plugin(CyberBikePlugin)
|
||||||
CyberBikePlugin,
|
.add_startup_system(disable_mouse_trap)
|
||||||
))
|
.add_system(bevy::window::close_on_esc);
|
||||||
.add_systems(Startup, disable_mouse_trap)
|
|
||||||
.add_systems(Update, close_on_esc);
|
|
||||||
|
|
||||||
#[cfg(feature = "inspector")]
|
#[cfg(feature = "inspector")]
|
||||||
app.add_plugin(CyberGlamorPlugin);
|
app.add_plugin(CyberGlamorPlugin);
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_on_esc(
|
|
||||||
mut commands: Commands,
|
|
||||||
focused_windows: Query<(Entity, &Window)>,
|
|
||||||
input: Res<ButtonInput<KeyCode>>,
|
|
||||||
) {
|
|
||||||
for (window, focus) in focused_windows.iter() {
|
|
||||||
if !focus.focused {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if input.just_pressed(KeyCode::Escape) {
|
|
||||||
commands.entity(window).despawn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue