WIP crisper camera controls (prevent overshooting when braking)
This commit is contained in:
parent
3cef44c4b2
commit
2e35f90a19
24
src/actor.rs
24
src/actor.rs
|
@ -822,6 +822,7 @@ fn handle_wants_acceleration(
|
|||
let mut thruster_on = false;
|
||||
if let (Some(mut engine), Some(accel)) = (engine, accel) {
|
||||
let mut delta_v = DVec3::ZERO;
|
||||
let mut allow_fullstop = false;
|
||||
let boost = engine.current_boost_factor;
|
||||
engine.currently_matching_velocity = false;
|
||||
|
||||
|
@ -836,7 +837,11 @@ fn handle_wants_acceleration(
|
|||
}
|
||||
|
||||
if accel.direction != DVec3::ZERO {
|
||||
// Player is pressing AWSD keys
|
||||
delta_v += (trans.rotation * accel.direction.as_vec3()).as_dvec3();
|
||||
} else if accel.brake {
|
||||
// Player is only pressing space
|
||||
allow_fullstop = true;
|
||||
}
|
||||
|
||||
if delta_v.length_squared() > 0.003 {
|
||||
|
@ -858,8 +863,25 @@ fn handle_wants_acceleration(
|
|||
* ENGINE_SPEED_FACTOR as f64
|
||||
* engine.current_boost_factor;
|
||||
|
||||
let final_accel = delta_v.normalize() * engine_factor * dt as f64;
|
||||
|
||||
// Apply acceleration to velocity
|
||||
**v += delta_v.normalize() * engine_factor * dt as f64;
|
||||
if allow_fullstop {
|
||||
if let Some(target_v) = closest_map.get(&entity) {
|
||||
// Prevent overshooting when matching velocity, which
|
||||
// would result in oscillating acceleration back and forth
|
||||
for axis in 0..3 {
|
||||
let original = v[axis];
|
||||
let target = target_v[axis];
|
||||
v[axis] += final_accel[axis];
|
||||
if (original - target).signum() != (v[axis] - target).signum() {
|
||||
v[axis] = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
**v += final_accel;
|
||||
}
|
||||
|
||||
// Visual effect
|
||||
if engine.engine_type == EngineType::Monopropellant {
|
||||
|
|
Loading…
Reference in a new issue