switch to rapier character controller
it already supports custom gravity and custom up direction
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
use avian3d::{PhysicsPlugins, prelude::*};
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
window::{CursorGrabMode, PrimaryWindow},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
camera::{CameraPitch, CameraRoot, FollowCam, MainCamera, Unfocused},
|
||||
character_controller::CharacterController,
|
||||
tags::{Player, Ship},
|
||||
},
|
||||
plugins::*,
|
||||
};
|
||||
// use bevy_rapier3d::prelude::*;
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
window::{CursorGrabMode, PrimaryWindow},
|
||||
};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GamePlugin;
|
||||
@@ -24,14 +21,13 @@ impl Plugin for GamePlugin {
|
||||
// ShipPlugin,
|
||||
TypesPlugin,
|
||||
PlayerPlugin,
|
||||
CharacterControllerPlugin,
|
||||
// CharacterControllerPlugin,
|
||||
));
|
||||
app.add_plugins((
|
||||
PhysicsPlugins::default(),
|
||||
RapierPhysicsPlugin::<NoUserData>::default(),
|
||||
#[cfg(feature = "dev-phys")]
|
||||
PhysicsDebugPlugin::default(),
|
||||
RapierDebugRenderPlugin::default(),
|
||||
));
|
||||
app.insert_resource(Gravity::ZERO);
|
||||
app.add_systems(Startup, (setup_scene).chain());
|
||||
|
||||
app.add_systems(Update, camera_toggle);
|
||||
@@ -43,18 +39,17 @@ fn setup_scene(
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut window: Single<&mut Window, With<PrimaryWindow>>,
|
||||
mut gravity: ResMut<Gravity>,
|
||||
) {
|
||||
gravity.0 = Vec3::ZERO;
|
||||
|
||||
// window.cursor_options.visible = false;
|
||||
// window.cursor_options.grab_mode = CursorGrabMode::Locked;
|
||||
|
||||
let player = commands
|
||||
.spawn((
|
||||
Name::new("Player"),
|
||||
CharacterController::default(),
|
||||
Player,
|
||||
Collider::capsule_y(0.5, 0.5),
|
||||
RigidBody::KinematicPositionBased,
|
||||
KinematicCharacterController::default(),
|
||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::linear_rgb(1.0, 0.0, 0.2))),
|
||||
Transform::from_translation(Vec3::new(0.0, 10.0, 10.0)),
|
||||
@@ -96,7 +91,7 @@ fn setup_scene(
|
||||
Mesh3d(cube),
|
||||
MeshMaterial3d(material),
|
||||
Transform::default(),
|
||||
RigidBody::Static,
|
||||
RigidBody::Fixed,
|
||||
Collider::cuboid(100.0, 0.1, 100.0),
|
||||
));
|
||||
}
|
||||
@@ -117,8 +112,8 @@ fn spawn_ship(
|
||||
MeshMaterial3d(material.clone()),
|
||||
Name::new("Ship"),
|
||||
Ship,
|
||||
LinearDamping::default(),
|
||||
AngularDamping::default(),
|
||||
Velocity::zero(),
|
||||
Damping::default(),
|
||||
Transform::from_xyz(0.0, 1.0, 0.0),
|
||||
RigidBody::Dynamic,
|
||||
children![
|
||||
|
||||
Reference in New Issue
Block a user