Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ep 2 - 3D Basics, Resources, and code organization #2

Merged
merged 11 commits into from
Jul 18, 2024
Prev Previous commit
Next Next commit
update spaceship.rs to use bundle
  • Loading branch information
rahmatnazali committed Jul 18, 2024
commit 3198429acbf4b08d9b13a3647900840ac940a4f1
29 changes: 22 additions & 7 deletions src/spaceship.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use bevy::prelude::{App, Commands, Plugin, SpatialBundle, Startup, Vec3};
use bevy::prelude::{
App, AssetServer, Bundle, Commands, default, Plugin, Res, SceneBundle, Startup, Transform, Vec3,
};

use crate::movement::Velocity;

const STARTING_TRANSLATION: Vec3 = Vec3::new(0.0, 0.0, -20.0);
const STARTING_VELOCITY: Vec3 = Vec3::new(0.0, 0.0, 1.0);

#[derive(Bundle)]
struct SpaceshipBundle {
velocity: Velocity,
model: SceneBundle,
}

pub struct SpaceshipPlugin;

impl Plugin for SpaceshipPlugin {
@@ -10,11 +21,15 @@ impl Plugin for SpaceshipPlugin {
}
}

fn spawn_spaceship(mut commands: Commands) {
commands.spawn((
SpatialBundle::default(),
Velocity {
value: Vec3::new(0.1, 0.2, 0.3),
fn spawn_spaceship(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(SpaceshipBundle {
velocity: Velocity {
value: STARTING_VELOCITY,
},
model: SceneBundle {
scene: asset_server.load("Spaceship.glb#Scene0"),
transform: Transform::from_translation(STARTING_TRANSLATION),
..default()
},
));
});
}