cyber_rider/src/geometry.rs

70 lines
1.9 KiB
Rust
Raw Normal View History

use bevy::prelude::*;
use heron::prelude::{CollisionShape, RigidBody};
pub const PLANET_RADIUS: f32 = 350.0;
2022-01-14 00:14:08 +00:00
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
#[derive(Component, Debug)]
pub struct CyberBike;
2022-01-14 00:14:08 +00:00
#[derive(Component)]
pub struct CyberSphere;
fn spawn_giant_sphere(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands
.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere {
radius: PLANET_RADIUS,
subdivisions: 8,
})),
material: materials.add(StandardMaterial {
base_color: Color::GRAY,
metallic: 0.7,
perceptual_roughness: 0.5,
..Default::default()
}),
..Default::default()
})
2022-01-14 00:14:08 +00:00
.insert(CyberSphere)
.insert(RigidBody::Static)
.insert(CollisionShape::Sphere {
radius: PLANET_RADIUS,
});
}
2022-01-14 00:14:08 +00:00
fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
use crate::action::CyberBikeState;
commands
.spawn_bundle((
Transform {
2022-01-14 00:14:08 +00:00
translation: Vec3::new(SPAWN_ALTITUDE, 0.0, 0.0),
..Default::default()
}
.looking_at(Vec3::ZERO, Vec3::Y),
GlobalTransform::identity(),
))
.with_children(|rider| {
rider.spawn_scene(asset_server.load("cyber-bike_no_y_up.glb#Scene0"));
})
.insert(CyberBike)
.insert(RigidBody::Dynamic)
.insert(CollisionShape::Cone {
half_height: 2.0,
radius: 0.8,
})
2022-01-14 00:14:08 +00:00
.insert(CyberBikeState::default());
}
pub struct CyberGeomPlugin;
impl Plugin for CyberGeomPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(spawn_giant_sphere)
.add_startup_system(spawn_cyberbike);
}
}