Compare commits
2 commits
2358d53b7a
...
008ef5a3f8
Author | SHA1 | Date | |
---|---|---|---|
|
008ef5a3f8 | ||
|
c03779aa62 |
6 changed files with 1516 additions and 786 deletions
2210
Cargo.lock
generated
2210
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,9 +4,9 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
avian3d = "0.1.1"
|
||||
bevy = { version = "0.14.0", features = ["bevy_dev_tools"] }
|
||||
bevy-inspector-egui = "0.25.1"
|
||||
avian3d = { git = "https://github.com/Jondolf/avian.git" }
|
||||
bevy = { version = "0.15", features = ["bevy_dev_tools"] }
|
||||
bevy-inspector-egui = "0.28"
|
||||
|
||||
[features]
|
||||
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));
|
||||
|
||||
let bike = commands
|
||||
.spawn(SpatialBundle::from_transform(xform))
|
||||
.spawn((xform, Visibility::default()))
|
||||
.insert((
|
||||
Name::new("body"),
|
||||
RigidBody::Dynamic,
|
||||
|
@ -56,12 +56,11 @@ fn spawn_bike(
|
|||
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));
|
||||
rotation.rotate_x(FRAC_PI_2);
|
||||
let pbr_bundle = PbrBundle {
|
||||
mesh: meshes.add(Capsule3d::new(0.5, 1.45)),
|
||||
transform: rotation,
|
||||
material: materials.add(color),
|
||||
..Default::default()
|
||||
};
|
||||
let pbr_bundle = (
|
||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.45))),
|
||||
rotation,
|
||||
MeshMaterial3d(materials.add(color)),
|
||||
);
|
||||
builder.spawn(pbr_bundle);
|
||||
})
|
||||
.id();
|
||||
|
@ -163,25 +162,19 @@ fn wheels_helper(
|
|||
.spawn((
|
||||
Name::new("hub"),
|
||||
RigidBody::Dynamic,
|
||||
MassPropertiesBundle::new_computed(&Collider::sphere(0.1), 200.0),
|
||||
PbrBundle {
|
||||
mesh: meshes.add(hub_mesh),
|
||||
material: materials.add(wheel_material.clone()),
|
||||
transform: xform,
|
||||
..Default::default()
|
||||
},
|
||||
MassPropertiesBundle::from_shape(&Collider::sphere(0.1), 200.0),
|
||||
Mesh3d(meshes.add(hub_mesh)),
|
||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
||||
xform,
|
||||
))
|
||||
.id();
|
||||
|
||||
let tire = commands
|
||||
.spawn((
|
||||
Name::new("tire"),
|
||||
PbrBundle {
|
||||
mesh: meshes.add(tire_mesh),
|
||||
material: materials.add(wheel_material.clone()),
|
||||
transform: xform,
|
||||
..Default::default()
|
||||
},
|
||||
Mesh3d(meshes.add(tire_mesh)),
|
||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
||||
xform,
|
||||
CyberWheel,
|
||||
RigidBody::Dynamic,
|
||||
collider,
|
||||
|
|
|
@ -23,9 +23,7 @@ impl Default for DebugCamOffset {
|
|||
}
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands
|
||||
.spawn(Camera3dBundle::default())
|
||||
.insert(CyberCameras);
|
||||
commands.spawn(Camera3d::default()).insert(CyberCameras);
|
||||
}
|
||||
|
||||
fn update_camera_pos(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) {
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -1,5 +1,16 @@
|
|||
use avian3d::prelude::*;
|
||||
use bevy::{self, color::palettes::css::SILVER, prelude::*};
|
||||
use avian3d::prelude::{
|
||||
Collider, ColliderDensity, CollisionLayers, CollisionMargin, Friction, PhysicsGizmos, RigidBody,
|
||||
};
|
||||
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;
|
||||
|
||||
mod bike;
|
||||
|
@ -41,34 +52,36 @@ fn ground_and_light(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let spatial_bundle = (Transform::default(), Visibility::default());
|
||||
commands
|
||||
.spawn((
|
||||
SpatialBundle::default(),
|
||||
spatial_bundle,
|
||||
RigidBody::Static,
|
||||
Collider::cuboid(50.0, 0.5, 50.0),
|
||||
Collider::cuboid(50.0, 5., 50.0),
|
||||
CollisionMargin(0.1),
|
||||
ColliderDensity(1000.0),
|
||||
CollisionLayers::ALL,
|
||||
Friction::new(0.9),
|
||||
))
|
||||
.with_children(|p| {
|
||||
p.spawn(PbrBundle {
|
||||
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)),
|
||||
material: materials.add(Color::from(SILVER)),
|
||||
transform: Transform::from_xyz(0.0, 0.4, 0.0),
|
||||
..default()
|
||||
});
|
||||
let bundle = (
|
||||
Mesh3d(meshes.add(Plane3d::default().mesh().size(50.0, 50.0))),
|
||||
MeshMaterial3d(materials.add(Color::from(SILVER))),
|
||||
Transform::from_xyz(0.0, 2.5, 0.0),
|
||||
Visibility::Visible,
|
||||
);
|
||||
p.spawn(bundle);
|
||||
});
|
||||
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
intensity: 8_000_000.0,
|
||||
range: 100.,
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(8.0, 16.0, 8.0),
|
||||
..default()
|
||||
});
|
||||
Transform::from_xyz(8.0, 16.0, 8.0),
|
||||
));
|
||||
}
|
||||
|
||||
fn close_on_esc(
|
||||
|
|
|
@ -65,7 +65,7 @@ impl CatControllerState {
|
|||
}
|
||||
|
||||
mod systems {
|
||||
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||
use std::f32::consts::FRAC_PI_3;
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
|
@ -74,7 +74,7 @@ mod systems {
|
|||
use crate::bike::CyberBikeBody;
|
||||
|
||||
fn _yaw_to_angle(yaw: f32) -> f32 {
|
||||
let v = yaw.powi(5) * FRAC_PI_4;
|
||||
let v = yaw.powi(5) * FRAC_PI_3;
|
||||
if v.is_normal() {
|
||||
v
|
||||
} else {
|
||||
|
@ -146,7 +146,7 @@ mod systems {
|
|||
|
||||
// only try to correct roll if we're not totally vertical
|
||||
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_secs());
|
||||
let mag =
|
||||
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
|
||||
if mag.is_finite() {
|
||||
|
|
Loading…
Reference in a new issue