diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..ec26773 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,3 @@ +[target.x86_64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-Clink-arg=-fuse-ld=mold"] \ No newline at end of file diff --git a/.github/workflows/deploy-page.yaml b/.github/workflows/deploy-page.yaml index 6b35fce..1c5cde1 100644 --- a/.github/workflows/deploy-page.yaml +++ b/.github/workflows/deploy-page.yaml @@ -18,7 +18,7 @@ jobs: with: toolchain: stable - name: Install Dependencies - run: sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev + run: apt-get update; apt-get install --no-install-recommends -y pkg-config libx11-dev libasound2-dev libudev-dev libwayland-dev - name: Install trunk uses: jetli/trunk-action@v0.4.0 with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0dd2aba..677bf14 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -94,7 +94,7 @@ jobs: with: toolchain: stable - name: Install Dependencies - run: sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev + run: apt-get update; apt-get install -y pkg-config libx11-dev libasound2-dev libudev-dev - name: Build release run: | cargo build --profile dist @@ -180,7 +180,7 @@ jobs: with: toolchain: stable - name: Install Dependencies - run: sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev + run: apt-get update; apt-get install pkg-config libx11-dev libasound2-dev libudev-dev libwayland-dev - name: Install trunk uses: jetli/trunk-action@v0.4.0 with: diff --git a/.lapce/run.toml b/.lapce/run.toml new file mode 100644 index 0000000..6133a35 --- /dev/null +++ b/.lapce/run.toml @@ -0,0 +1,29 @@ +# The run config is used for both run mode and debug mode + +[[configs]] +# the name of this task +name = "[Dev] Build and run" + +# the type of the debugger. If not set, it can't be debugged but can still be run +# type = "lldb" + +# the program to run +program = "nix-shell" + +# the program arguments, e.g. args = ["arg1", "arg2"], optional +args = ["--run"] + +# current working directory, optional +# cwd = "${workspace}" + +# enviroment variables, optional +# [configs.env] +# VAR1 = "VAL1" +# VAR2 = "VAL2" + +# task to run before the run/debug session is started, optional +# [configs.prelaunch] +# program = "cargo" +# args = [ +# "build", +# ] diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c07dd5c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.debug.engine": "vadimcn.vscode-lldb", +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 57aa7c8..ae4d298 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,11 +23,7 @@ use bevy::prelude::*; use bevy_editor_pls::prelude::*; use bevy_xpbd_3d::prelude::*; -mod charcacter_controller; -mod input_processor; -mod player_look; - -use charcacter_controller::*; +use character_controller::*; use input_processor::*; use player_look::*; diff --git a/src/player_utils.rs b/src/player_utils.rs new file mode 100644 index 0000000..15b96f9 --- /dev/null +++ b/src/player_utils.rs @@ -0,0 +1,3 @@ +mod character_controller; +mod input_processor; +mod player_look; \ No newline at end of file diff --git a/src/charcacter_controller.rs b/src/player_utils/character_controller.rs similarity index 53% rename from src/charcacter_controller.rs rename to src/player_utils/character_controller.rs index 5cdf0d0..74417ff 100644 --- a/src/charcacter_controller.rs +++ b/src/player_utils/character_controller.rs @@ -16,15 +16,16 @@ along with this program. If not, see Vec3 { + // No acceleration in Z + let fall_acceleration = Vec3::new( + controller.gravity.x, + 0.0, + controller.gravity.y, + ); + + // Bound acceleration, falling object has minimal ability to impact acceleration + let mut acceleration = fall_acceleration; + if velocity.length_squared() > 0.0 { + acceleration *= controller.air_control_factor; + acceleration = acceleration.clamp_length(0.0, controller.movement_acceleration); + } + + acceleration +} + + +// function "borrowed" from UE +fn point_plane_project(point: Vec3, plane_base: Vec3, plane_normal: Vec3) -> Vec3 { + let projection = point - plane_normal * plane_normal.dot(point - plane_base); + projection +} + +// function "borrowed" from UE +fn new_fall_velocity(initial_velocity: LinearVelocity, gravity: Vec3, delta_time: f32, speed_limit: f32) +-> Vec3 { + + let mut result: Vec3 = Vec3 { x: initial_velocity.x, y: initial_velocity.y, z: initial_velocity.z }; + let terminal_velocity: f32 = 50.0; + + if delta_time > 0.0 + { + + // Apply gravity. + result += gravity * delta_time; + + + // Don't exceed terminal velocity. + let terminal_limit: f32 = f32::abs(terminal_velocity); //FMath::Abs(GetPhysicsVolume()->TerminalVelocity); + if result.length_squared() > (terminal_limit * terminal_limit) + { + let gravity_dir: Vec3 = gravity.normalize(); + + if result.y > terminal_limit || gravity_dir.y > terminal_limit + { + result = point_plane_project(result, Vec3::ZERO, gravity_dir) + gravity_dir * terminal_limit; + } + } + } + + result.z = f32::clamp(result.z, -speed_limit, speed_limit); + + return result; +} + +fn apply_gravity( + time: Res