use std::f32::consts::FRAC_PI_2; use bevy::input::mouse::MouseMotion; use bevy::prelude::*; use bevy::window::{Cursor, CursorGrabMode, PrimaryWindow}; use bevy_mod_wanderlust::{ ControllerBundle, ControllerInput, ControllerPhysicsBundle, WanderlustPlugin, }; use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin}; use bevy_rapier3d::prelude::*; fn main() { App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { cursor: Cursor { visible: false, grab_mode: CursorGrabMode::Locked, ..default() }, ..default() }), ..default() }), RapierPhysicsPlugin::::default(), WanderlustPlugin, aether_spyglass::SpyglassPlugin, )) .add_systems(Startup, setup) .add_systems( Update, ( input.before(bevy_mod_wanderlust::movement), toggle_cursor_lock, ), ) .register_type::() .run(); } #[derive(Component, Default, Reflect)] #[reflect(Component)] struct Player; fn setup( mut c: Commands, mut meshes: ResMut>, mut mats: ResMut>, ass: Res, ) { // Origin cube to be able to tell how you're moving let mesh = meshes.add(shape::Cube { size: 10.0 }.into()); let material = mats.add(Color::WHITE.into()); c.spawn(PbrBundle { mesh, material, transform: Transform::from_xyz(0.0, 0.0, 0.0), ..default() }); // Light so you can see the cube c.spawn(PointLightBundle { transform: Transform::from_xyz(15.0, 16.0, 17.0), point_light: PointLight { color: Color::default(), intensity: 8000.0, range: 50.0, ..default() }, ..default() }); // The ship itself c.spawn(( ControllerBundle { transform: Transform::from_xyz(0.0, 0.0, 5.0), physics: ControllerPhysicsBundle { damping: Damping { angular_damping: 0.5, linear_damping: 0.5, }, ..default() }, ..ControllerBundle::starship() }, Player, )) .with_children(|c| { c.spawn(SceneBundle { transform: Transform::from_translation(Vec3::ZERO).with_rotation(Quat::from_euler( EulerRot::XYZ, 0.0, -FRAC_PI_2, 0.0, )), scene: ass.load("gltf/starship.glb#Scene0"), ..default() }); c.spawn(Camera3dBundle { transform: Transform::from_xyz(0.0, 7.5, 35.0), ..default() }); }); } fn input( mut body: Query<(&mut ControllerInput, &GlobalTransform, &mut ExternalImpulse)>, input: Res>, mut mouse: EventReader, time: Res