MASSIVE Kinematic Character Controller Update
- NEW kinematic character controller powered by rapier3d at kinematic_character_controller.rs - NEW camera modes. The ability to switch between the free debug camera and new character controller. - NEW keybinds system to support the camera mode swap
This commit is contained in:
parent
8b5a6167eb
commit
713d865dd7
12 changed files with 323 additions and 26 deletions
|
|
@ -1,14 +1,14 @@
|
|||
mod systems;
|
||||
use std::fmt::format;
|
||||
use glam::{Quat, Vec3};
|
||||
use rapier3d::dynamics::RigidBodyType;
|
||||
use rapier3d::dynamics::{CoefficientCombineRule, RigidBodyType};
|
||||
use rapier3d::prelude::ColliderBuilder;
|
||||
use raidillon_engine::{Engine, system::System, EngineResources};
|
||||
use raidillon_engine::{Engine, system::System, EngineResources, InputState};
|
||||
use raidillon_engine::system::SystemContext;
|
||||
use raidillon_platform::{Platform, Camera, PlatformContext};
|
||||
use raidillon_assets::model_path;
|
||||
use raidillon_core::engine::EngineTrait;
|
||||
use raidillon_ecs::components::{ModelHandle, RigidBodyComponent};
|
||||
use raidillon_ecs::components::{CameraMode, CharacterBodyComponent, ModelHandle, RigidBodyComponent};
|
||||
use raidillon_ecs::Transform;
|
||||
use raidillon_core::scene::Scene;
|
||||
#[cfg(feature = "glium")]
|
||||
|
|
@ -18,8 +18,9 @@ use winit::event::DeviceEvent::MouseMotion;
|
|||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use raidillon_core::DebugUIBuffer;
|
||||
use raidillon_engine::systems::fps_camera::FPSDebugCameraSystem;
|
||||
use raidillon_glium::RenderingSystem;
|
||||
use raidillon_physics::Physics;
|
||||
use crate::systems::PhysicsSystem;
|
||||
use crate::systems::{KeybindsSystem, KinematicCharacterController, PhysicsSystem};
|
||||
|
||||
const TEST_GLTF: &str = "sphere.glb";
|
||||
const PLANE_GLTF: &str = "plane.glb";
|
||||
|
|
@ -50,7 +51,7 @@ struct RenderingTestSystem;
|
|||
impl System for RenderingTestSystem {
|
||||
fn load_world(&mut self, res: &mut EngineResources, scene: &mut Scene) {
|
||||
let pctx = res.get::<PlatformContext>().expect("PlatformContext missing").clone();
|
||||
let physics = res.get_mut::<Physics>().expect("Physics missing");
|
||||
let physics = scene.resources.get_mut::<Physics>().expect("Physics missing");
|
||||
|
||||
// Spawn Sphere
|
||||
{
|
||||
|
|
@ -59,7 +60,10 @@ impl System for RenderingTestSystem {
|
|||
rotation: Quat::IDENTITY,
|
||||
scale: Vec3::new(1.0, 1.0, 1.0),
|
||||
};
|
||||
let collider = ColliderBuilder::ball(1.0).build();
|
||||
let collider = ColliderBuilder::ball(1.0)
|
||||
.restitution(0.7)
|
||||
.restitution_combine_rule(CoefficientCombineRule::Max)
|
||||
.build();
|
||||
let rb_handle = physics.add_rigid_body(RigidBodyType::Dynamic, tr, collider);
|
||||
pctx.asset_manager.borrow_mut().load_gltf(TEST_GLTF, &model_path(TEST_GLTF));
|
||||
scene.world.spawn((
|
||||
|
|
@ -84,16 +88,32 @@ impl System for RenderingTestSystem {
|
|||
RigidBodyComponent(rb_handle),
|
||||
));
|
||||
}
|
||||
|
||||
scene.world.spawn((Camera {
|
||||
eye: Vec3::new(0.0, 2.0, 3.0),
|
||||
center: Vec3::ZERO,
|
||||
up: Vec3::Y,
|
||||
fovy: 60_f32.to_radians(),
|
||||
aspect: pctx.frame_width / pctx.frame_height,
|
||||
znear: 0.1,
|
||||
zfar: 100.0},
|
||||
CameraMode::default(),
|
||||
));
|
||||
}
|
||||
|
||||
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
|
||||
let pctx = res.get::<PlatformContext>().unwrap();
|
||||
let input = res.get::<InputState>().unwrap();
|
||||
let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap();
|
||||
|
||||
dbg_ui.text("Hello World!".to_owned());
|
||||
dbg_ui.text(format!("Frame Delta: {}", pctx.time_ctx.frame_dt));
|
||||
dbg_ui.text(format!("Fixed Delta: {}", pctx.time_ctx.fixed_dt));
|
||||
dbg_ui.text(format!("FPS: {}", 1.0 / pctx.time_ctx.frame_dt));
|
||||
|
||||
for (_ent, (tr, ch_component)) in scene.world.query::<(&Transform, &CharacterBodyComponent)>().iter() {
|
||||
dbg_ui.text(format!("Character POS: {}", tr.translation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +121,8 @@ fn main() {
|
|||
let mut engine = Engine::new();
|
||||
// Define systems
|
||||
engine.system_manager.add::<PhysicsSystem>();
|
||||
engine.system_manager.add::<FPSDebugCameraSystem>();
|
||||
engine.system_manager.add::<KeybindsSystem>();
|
||||
engine.system_manager.add::<KinematicCharacterController>();
|
||||
engine.system_manager.add::<RenderingTestSystem>();
|
||||
engine.system_manager.add::<UpdateAspectRatioSystem>();
|
||||
// engine.system_manager.add::<InputTestSystem>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue