disabled running cargo check on save in rust analizer, did a little bit of work on character controller

This commit is contained in:
NIMFER 2024-05-16 01:57:10 +02:00
parent e07cb2ff2f
commit 576a9b1d40
5 changed files with 84 additions and 102 deletions

View file

@ -1,29 +0,0 @@
# 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",
# ]

6
.vscode/launch.json vendored
View file

@ -17,6 +17,12 @@
"request": "launch",
"type": "node-terminal"
},
{
"command": "nix-shell --run 'cargo check'",
"name": "Check for errors",
"request": "launch",
"type": "node-terminal"
},
{
"type": "lldb",
"request": "launch",

View file

@ -6,4 +6,5 @@
"Substep",
"xpbd"
],
"rust-analyzer.checkOnSave": false,
}

View file

@ -31,6 +31,11 @@ lto = true
codegen-units = 1
strip = true
[build]
rustflags = ["-Z", "threads=7"]
[features]
dev = [
"bevy/dynamic_linking",

View file

@ -226,7 +226,7 @@ fn move_character(
character_transform,
) in &mut query
{
character_controller.friction = f32::max(0.0f, character_controller.friction);
//character_controller.friction = f32::max(0.0, character_controller.friction);
let forward = character_transform.forward().xyz().normalize();
match event {
@ -248,6 +248,77 @@ fn move_character(
}
}
fn move_character(
time: Res<Time>,
mut movement_event_reader: EventReader<MovementAction>,
mut query: Query<(
&mut LinearVelocity,
&CharacterController,
Has<Grounded>,
&Rotation,
&ShapeHits,
&Transform,
)>,
) {
let delta_time = time.delta_seconds_f64().adjust_precision();
for event in movement_event_reader.read() {
for (
mut velocity,
character_controller,
is_grounded,
rotation,
shape_hits,
character_transform,
) in &mut query
{
match event {
MovementAction::Move(direction) => {
// Get the forward direction of the character in the local coordinate system
let forward = character_transform.forward().xyz().normalize();
// Calculate the movement in the local coordinate system
let local_movement = forward
* direction.y
* character_controller.movement_acceleration
* delta_time
+ character_transform
.rotation
.mul_vec3(Vec3::new(direction.x, 0.0, 0.0))
* character_controller.movement_acceleration
* delta_time;
if is_grounded {
let mut slope_factor = 1.0;
for hit in shape_hits.iter() {
let angle =
rotation.rotate(-hit.normal2).angle_between(Vector::Y).abs();
if angle <= character_controller.max_slope_angle {
slope_factor *=
(angle / character_controller.max_slope_angle).cos();
// Update linear velocity
velocity.x += local_movement.x * slope_factor;
velocity.z += local_movement.z * slope_factor;
} else {
velocity.x = 0.0;
velocity.z = 0.0;
}
}
} else {
velocity.x += local_movement.x * character_controller.air_control_factor;
velocity.z += local_movement.z * character_controller.air_control_factor;
}
}
MovementAction::Jump => {
if is_grounded {
velocity.y = character_controller.jump_impulse;
}
}
}
}
}
}
fn update_grounded(
mut commands: Commands,
@ -347,78 +418,6 @@ fn kinematic_controller_collisions(
}
}
// fn move_character(
// time: Res<Time>,
// mut movement_event_reader: EventReader<MovementAction>,
// mut query: Query<(
// &mut LinearVelocity,
// &CharacterController,
// Has<Grounded>,
// &Rotation,
// &ShapeHits,
// &Transform,
// )>,
// ) {
// let delta_time = time.delta_seconds_f64().adjust_precision();
// for event in movement_event_reader.read() {
// for (
// mut velocity,
// character_controller,
// is_grounded,
// rotation,
// shape_hits,
// character_transform,
// ) in &mut query
// {
// match event {
// MovementAction::Move(direction) => {
// // Get the forward direction of the character in the local coordinate system
// let forward = character_transform.forward().xyz().normalize();
// // Calculate the movement in the local coordinate system
// let local_movement = forward
// * direction.y
// * character_controller.movement_acceleration
// * delta_time
// + character_transform
// .rotation
// .mul_vec3(Vec3::new(direction.x, 0.0, 0.0))
// * character_controller.movement_acceleration
// * delta_time;
// if is_grounded {
// let mut slope_factor = 1.0;
// for hit in shape_hits.iter() {
// let angle =
// rotation.rotate(-hit.normal2).angle_between(Vector::Y).abs();
// if angle <= character_controller.max_slope_angle {
// slope_factor *=
// (angle / character_controller.max_slope_angle).cos();
// // Update linear velocity
// velocity.x += local_movement.x * slope_factor;
// velocity.z += local_movement.z * slope_factor;
// } else {
// velocity.x = 0.0;
// velocity.z = 0.0;
// }
// }
// } else {
// velocity.x += local_movement.x * character_controller.air_control_factor;
// velocity.z += local_movement.z * character_controller.air_control_factor;
// }
// }
// MovementAction::Jump => {
// if is_grounded {
// velocity.y = character_controller.jump_impulse;
// }
// }
// }
// }
// }
// }
fn dampen_movement(mut qeury: Query<(&mut LinearVelocity, &CharacterController)>) {
for (mut velocity, character_controller) in &mut qeury {
// We could use `LinearDamping`, but we don't want to dampen movement along the Y axis