Compare commits
No commits in common. "008ef5a3f8f11807932f3d9e1f052f9df4d017ea" and "2358d53b7a060a323c25882ff1b61ac15586973d" have entirely different histories.
008ef5a3f8
...
2358d53b7a
6 changed files with 772 additions and 1502 deletions
2182
Cargo.lock
generated
2182
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,9 +4,9 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
avian3d = { git = "https://github.com/Jondolf/avian.git" }
|
avian3d = "0.1.1"
|
||||||
bevy = { version = "0.15", features = ["bevy_dev_tools"] }
|
bevy = { version = "0.14.0", features = ["bevy_dev_tools"] }
|
||||||
bevy-inspector-egui = "0.28"
|
bevy-inspector-egui = "0.25.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
no-mesh = []
|
no-mesh = []
|
||||||
|
|
33
src/bike.rs
33
src/bike.rs
|
@ -35,7 +35,7 @@ fn spawn_bike(
|
||||||
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 bike = commands
|
let bike = commands
|
||||||
.spawn((xform, Visibility::default()))
|
.spawn(SpatialBundle::from_transform(xform))
|
||||||
.insert((
|
.insert((
|
||||||
Name::new("body"),
|
Name::new("body"),
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
|
@ -56,11 +56,12 @@ fn spawn_bike(
|
||||||
let color = Color::srgb(0.7, 0.05, 0.7);
|
let color = Color::srgb(0.7, 0.05, 0.7);
|
||||||
let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2));
|
let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2));
|
||||||
rotation.rotate_x(FRAC_PI_2);
|
rotation.rotate_x(FRAC_PI_2);
|
||||||
let pbr_bundle = (
|
let pbr_bundle = PbrBundle {
|
||||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.45))),
|
mesh: meshes.add(Capsule3d::new(0.5, 1.45)),
|
||||||
rotation,
|
transform: rotation,
|
||||||
MeshMaterial3d(materials.add(color)),
|
material: materials.add(color),
|
||||||
);
|
..Default::default()
|
||||||
|
};
|
||||||
builder.spawn(pbr_bundle);
|
builder.spawn(pbr_bundle);
|
||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
|
@ -162,19 +163,25 @@ fn wheels_helper(
|
||||||
.spawn((
|
.spawn((
|
||||||
Name::new("hub"),
|
Name::new("hub"),
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
MassPropertiesBundle::from_shape(&Collider::sphere(0.1), 200.0),
|
MassPropertiesBundle::new_computed(&Collider::sphere(0.1), 200.0),
|
||||||
Mesh3d(meshes.add(hub_mesh)),
|
PbrBundle {
|
||||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
mesh: meshes.add(hub_mesh),
|
||||||
xform,
|
material: materials.add(wheel_material.clone()),
|
||||||
|
transform: xform,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let tire = commands
|
let tire = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Name::new("tire"),
|
Name::new("tire"),
|
||||||
Mesh3d(meshes.add(tire_mesh)),
|
PbrBundle {
|
||||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
mesh: meshes.add(tire_mesh),
|
||||||
xform,
|
material: materials.add(wheel_material.clone()),
|
||||||
|
transform: xform,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
CyberWheel,
|
CyberWheel,
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
collider,
|
collider,
|
||||||
|
|
|
@ -23,7 +23,9 @@ impl Default for DebugCamOffset {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_camera(mut commands: Commands) {
|
fn spawn_camera(mut commands: Commands) {
|
||||||
commands.spawn(Camera3d::default()).insert(CyberCameras);
|
commands
|
||||||
|
.spawn(Camera3dBundle::default())
|
||||||
|
.insert(CyberCameras);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_camera_pos(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) {
|
fn update_camera_pos(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) {
|
||||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -1,16 +1,5 @@
|
||||||
use avian3d::prelude::{
|
use avian3d::prelude::*;
|
||||||
Collider, ColliderDensity, CollisionLayers, CollisionMargin, Friction, PhysicsGizmos, RigidBody,
|
use bevy::{self, color::palettes::css::SILVER, prelude::*};
|
||||||
};
|
|
||||||
use bevy::{
|
|
||||||
color::palettes::css::SILVER,
|
|
||||||
pbr::MeshMaterial3d,
|
|
||||||
prelude::{
|
|
||||||
default, App, AppGizmoBuilder, Assets, BuildChildren, ButtonInput, ChildBuild, Color,
|
|
||||||
Commands, DefaultPlugins, Entity, GizmoConfig, KeyCode, Mesh, Mesh3d, Meshable, Plane3d,
|
|
||||||
PointLight, Query, Res, ResMut, Srgba, StandardMaterial, Startup, Transform, Update, Vec3,
|
|
||||||
Visibility, Window,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||||
|
|
||||||
mod bike;
|
mod bike;
|
||||||
|
@ -52,36 +41,34 @@ fn ground_and_light(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let spatial_bundle = (Transform::default(), Visibility::default());
|
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
spatial_bundle,
|
SpatialBundle::default(),
|
||||||
RigidBody::Static,
|
RigidBody::Static,
|
||||||
Collider::cuboid(50.0, 5., 50.0),
|
Collider::cuboid(50.0, 0.5, 50.0),
|
||||||
CollisionMargin(0.1),
|
CollisionMargin(0.1),
|
||||||
ColliderDensity(1000.0),
|
ColliderDensity(1000.0),
|
||||||
CollisionLayers::ALL,
|
|
||||||
Friction::new(0.9),
|
Friction::new(0.9),
|
||||||
))
|
))
|
||||||
.with_children(|p| {
|
.with_children(|p| {
|
||||||
let bundle = (
|
p.spawn(PbrBundle {
|
||||||
Mesh3d(meshes.add(Plane3d::default().mesh().size(50.0, 50.0))),
|
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
||||||
MeshMaterial3d(materials.add(Color::from(SILVER))),
|
material: materials.add(Color::from(SILVER)),
|
||||||
Transform::from_xyz(0.0, 2.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.4, 0.0),
|
||||||
Visibility::Visible,
|
..default()
|
||||||
);
|
});
|
||||||
p.spawn(bundle);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn(PointLightBundle {
|
||||||
PointLight {
|
point_light: PointLight {
|
||||||
intensity: 8_000_000.0,
|
intensity: 8_000_000.0,
|
||||||
range: 100.,
|
range: 100.,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Transform::from_xyz(8.0, 16.0, 8.0),
|
transform: Transform::from_xyz(8.0, 16.0, 8.0),
|
||||||
));
|
..default()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_on_esc(
|
fn close_on_esc(
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl CatControllerState {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod systems {
|
mod systems {
|
||||||
use std::f32::consts::FRAC_PI_3;
|
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||||
|
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
@ -74,7 +74,7 @@ mod systems {
|
||||||
use crate::bike::CyberBikeBody;
|
use crate::bike::CyberBikeBody;
|
||||||
|
|
||||||
fn _yaw_to_angle(yaw: f32) -> f32 {
|
fn _yaw_to_angle(yaw: f32) -> f32 {
|
||||||
let v = yaw.powi(5) * FRAC_PI_3;
|
let v = yaw.powi(5) * FRAC_PI_4;
|
||||||
if v.is_normal() {
|
if v.is_normal() {
|
||||||
v
|
v
|
||||||
} else {
|
} else {
|
||||||
|
@ -146,7 +146,7 @@ mod systems {
|
||||||
|
|
||||||
// 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_secs());
|
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds());
|
||||||
let mag =
|
let mag =
|
||||||
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
|
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
|
||||||
if mag.is_finite() {
|
if mag.is_finite() {
|
||||||
|
|
Loading…
Reference in a new issue