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"
|
||||
|
||||
[dependencies]
|
||||
avian3d = { git = "https://github.com/Jondolf/avian.git" }
|
||||
bevy = { version = "0.15", features = ["bevy_dev_tools"] }
|
||||
bevy-inspector-egui = "0.28"
|
||||
avian3d = "0.1.1"
|
||||
bevy = { version = "0.14.0", features = ["bevy_dev_tools"] }
|
||||
bevy-inspector-egui = "0.25.1"
|
||||
|
||||
[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((xform, Visibility::default()))
|
||||
.spawn(SpatialBundle::from_transform(xform))
|
||||
.insert((
|
||||
Name::new("body"),
|
||||
RigidBody::Dynamic,
|
||||
|
@ -56,11 +56,12 @@ 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 = (
|
||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.45))),
|
||||
rotation,
|
||||
MeshMaterial3d(materials.add(color)),
|
||||
);
|
||||
let pbr_bundle = PbrBundle {
|
||||
mesh: meshes.add(Capsule3d::new(0.5, 1.45)),
|
||||
transform: rotation,
|
||||
material: materials.add(color),
|
||||
..Default::default()
|
||||
};
|
||||
builder.spawn(pbr_bundle);
|
||||
})
|
||||
.id();
|
||||
|
@ -162,19 +163,25 @@ fn wheels_helper(
|
|||
.spawn((
|
||||
Name::new("hub"),
|
||||
RigidBody::Dynamic,
|
||||
MassPropertiesBundle::from_shape(&Collider::sphere(0.1), 200.0),
|
||||
Mesh3d(meshes.add(hub_mesh)),
|
||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
||||
xform,
|
||||
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()
|
||||
},
|
||||
))
|
||||
.id();
|
||||
|
||||
let tire = commands
|
||||
.spawn((
|
||||
Name::new("tire"),
|
||||
Mesh3d(meshes.add(tire_mesh)),
|
||||
MeshMaterial3d(materials.add(wheel_material.clone())),
|
||||
xform,
|
||||
PbrBundle {
|
||||
mesh: meshes.add(tire_mesh),
|
||||
material: materials.add(wheel_material.clone()),
|
||||
transform: xform,
|
||||
..Default::default()
|
||||
},
|
||||
CyberWheel,
|
||||
RigidBody::Dynamic,
|
||||
collider,
|
||||
|
|
|
@ -23,7 +23,9 @@ impl Default for DebugCamOffset {
|
|||
}
|
||||
|
||||
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>>) {
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -1,16 +1,5 @@
|
|||
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 avian3d::prelude::*;
|
||||
use bevy::{self, color::palettes::css::SILVER, prelude::*};
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
||||
mod bike;
|
||||
|
@ -52,36 +41,34 @@ fn ground_and_light(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let spatial_bundle = (Transform::default(), Visibility::default());
|
||||
commands
|
||||
.spawn((
|
||||
spatial_bundle,
|
||||
SpatialBundle::default(),
|
||||
RigidBody::Static,
|
||||
Collider::cuboid(50.0, 5., 50.0),
|
||||
Collider::cuboid(50.0, 0.5, 50.0),
|
||||
CollisionMargin(0.1),
|
||||
ColliderDensity(1000.0),
|
||||
CollisionLayers::ALL,
|
||||
Friction::new(0.9),
|
||||
))
|
||||
.with_children(|p| {
|
||||
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);
|
||||
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()
|
||||
});
|
||||
});
|
||||
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
intensity: 8_000_000.0,
|
||||
range: 100.,
|
||||
shadows_enabled: true,
|
||||
..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(
|
||||
|
|
|
@ -65,7 +65,7 @@ impl CatControllerState {
|
|||
}
|
||||
|
||||
mod systems {
|
||||
use std::f32::consts::FRAC_PI_3;
|
||||
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
|
||||
|
||||
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_3;
|
||||
let v = yaw.powi(5) * FRAC_PI_4;
|
||||
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_secs());
|
||||
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds());
|
||||
let mag =
|
||||
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
|
||||
if mag.is_finite() {
|
||||
|
|
Loading…
Reference in a new issue