cyber_rider/src/geometry.rs

68 lines
1.9 KiB
Rust
Raw Normal View History

use bevy::prelude::*;
use heron::prelude::{CollisionShape, RigidBody};
pub const PLANET_RADIUS: f32 = 150.0;
pub(crate) const PLAYER_DIST: f32 = PLANET_RADIUS + 100.0;
pub struct CyberGeomPlugin;
impl Plugin for CyberGeomPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(setup_giant_sphere)
.add_startup_system(setup_player);
}
}
#[derive(Component, Debug)]
pub struct CyberBike;
fn setup_giant_sphere(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// world
commands
.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere {
radius: PLANET_RADIUS,
subdivisions: 6,
})),
material: materials.add(StandardMaterial {
base_color: Color::GRAY,
metallic: 0.7,
perceptual_roughness: 0.5,
..Default::default()
}),
..Default::default()
})
.insert(RigidBody::Static)
.insert(CollisionShape::Sphere {
radius: PLANET_RADIUS,
});
}
fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
use crate::physics::PlayerState;
commands
.spawn_bundle((
Transform {
translation: Vec3::new(PLAYER_DIST, 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,
})
.insert(PlayerState::default());
}