The physics sim bits (that aren't Rapier2d) are now in their own submodule. I've included the `Wrapping` marker component because it doesn't really have anywhere else to live, and it's kinda sorta related to the physics. It controls the motion of objects... that's physics. :p There are name collisions between Rapier2d's `Velocity` and my own, but that's a problem for later. I've used more specific type paths where necessary to maintain the previous behavior. The `physics::Position` component can go away completely. It's just an extra copy of some of the built-in `Transform` data. I'm pretty sure it only exists because I didn't realize I could rely on directly manipulating the transform when I started this project.
33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
use bevy::prelude::*;
|
|
use bevy_rapier2d::prelude::*;
|
|
|
|
use crate::{GameAssets, Rotation, physics::Position, physics::Velocity, physics::Wrapping};
|
|
|
|
#[derive(Component)]
|
|
pub struct Ship;
|
|
|
|
pub fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
|
|
commands
|
|
.spawn((
|
|
Collider::ball(0.7),
|
|
Sensor,
|
|
ActiveEvents::COLLISION_EVENTS,
|
|
ActiveCollisionTypes::STATIC_STATIC,
|
|
Ship,
|
|
Wrapping,
|
|
Position(Vec2::default()),
|
|
Velocity(Vec2::ZERO),
|
|
Rotation(0.0),
|
|
Mesh2d(game_assets.ship().0),
|
|
MeshMaterial2d(game_assets.ship().1),
|
|
Transform::default().with_scale(Vec3::new(20.0, 20.0, 20.0)),
|
|
))
|
|
.with_child((
|
|
Mesh2d(game_assets.thruster_mesh()),
|
|
MeshMaterial2d(game_assets.thruster_mat_inactive()),
|
|
Transform::default()
|
|
.with_scale(Vec3::splat(0.5))
|
|
.with_translation(Vec3::new(-0.5, 0.0, -0.1)),
|
|
));
|
|
}
|