mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'lboklin/glider-take-off' into 'master'
Fix glider pitching down when trying to take off See merge request veloren/veloren!2233
This commit is contained in:
commit
4d09180ddb
@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
|
const PITCH_SLOW_TIME: f32 = 0.5;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
/// The aspect ratio is the ratio of the span squared to actual planform
|
/// The aspect ratio is the ratio of the span squared to actual planform
|
||||||
@ -19,6 +21,7 @@ pub struct Data {
|
|||||||
pub planform_area: f32,
|
pub planform_area: f32,
|
||||||
pub ori: Ori,
|
pub ori: Ori,
|
||||||
last_vel: Vel,
|
last_vel: Vel,
|
||||||
|
timer: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
@ -36,11 +39,11 @@ impl Data {
|
|||||||
planform_area,
|
planform_area,
|
||||||
ori,
|
ori,
|
||||||
last_vel: Vel::zero(),
|
last_vel: Vel::zero(),
|
||||||
|
timer: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn tgt_dir(data: &JoinData) -> Dir {
|
fn tgt_dir(&self, data: &JoinData) -> Dir {
|
||||||
let look_ori = Ori::from(data.inputs.look_dir);
|
let look_ori = Ori::from(data.inputs.look_dir);
|
||||||
look_ori
|
look_ori
|
||||||
.yawed_right(PI / 3.0 * look_ori.right().xy().dot(data.inputs.move_dir))
|
.yawed_right(PI / 3.0 * look_ori.right().xy().dot(data.inputs.move_dir))
|
||||||
@ -50,9 +53,13 @@ fn tgt_dir(data: &JoinData) -> Dir {
|
|||||||
.look_dir
|
.look_dir
|
||||||
.xy()
|
.xy()
|
||||||
.try_normalized()
|
.try_normalized()
|
||||||
.map_or(0.0, |ld| PI * 0.1 * ld.dot(data.inputs.move_dir)),
|
.map_or(0.0, |ld| {
|
||||||
|
PI * 0.1 * ld.dot(data.inputs.move_dir) * self.timer.min(PITCH_SLOW_TIME)
|
||||||
|
/ PITCH_SLOW_TIME
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.look_dir()
|
.look_dir()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharacterBehavior for Data {
|
impl CharacterBehavior for Data {
|
||||||
@ -86,7 +93,7 @@ impl CharacterBehavior for Data {
|
|||||||
|
|
||||||
Dir::from_unnormalized(air_flow.0)
|
Dir::from_unnormalized(air_flow.0)
|
||||||
.map(|flow_dir| {
|
.map(|flow_dir| {
|
||||||
let tgt_dir = tgt_dir(data);
|
let tgt_dir = self.tgt_dir(data);
|
||||||
let tgt_dir_ori = Ori::from(tgt_dir);
|
let tgt_dir_ori = Ori::from(tgt_dir);
|
||||||
let tgt_dir_up = tgt_dir_ori.up();
|
let tgt_dir_up = tgt_dir_ori.up();
|
||||||
// The desired up vector of our glider.
|
// The desired up vector of our glider.
|
||||||
@ -110,7 +117,9 @@ impl CharacterBehavior for Data {
|
|||||||
})
|
})
|
||||||
.unwrap_or_else(Dir::up);
|
.unwrap_or_else(Dir::up);
|
||||||
let global_roll = tgt_dir_up.rotation_between(tgt_up);
|
let global_roll = tgt_dir_up.rotation_between(tgt_up);
|
||||||
let global_pitch = angle_of_attack(&tgt_dir_ori, &flow_dir);
|
let global_pitch = angle_of_attack(&tgt_dir_ori, &flow_dir)
|
||||||
|
* self.timer.min(PITCH_SLOW_TIME)
|
||||||
|
/ PITCH_SLOW_TIME;
|
||||||
|
|
||||||
self.ori.slerped_towards(
|
self.ori.slerped_towards(
|
||||||
tgt_dir_ori.prerotated(global_roll).pitched_up(global_pitch),
|
tgt_dir_ori.prerotated(global_roll).pitched_up(global_pitch),
|
||||||
@ -145,7 +154,7 @@ impl CharacterBehavior for Data {
|
|||||||
let accel_factor = accel.magnitude_squared().min(1.0) / 1.0;
|
let accel_factor = accel.magnitude_squared().min(1.0) / 1.0;
|
||||||
|
|
||||||
Quaternion::rotation_3d(
|
Quaternion::rotation_3d(
|
||||||
PI / 2.0 * accel_factor,
|
PI / 2.0 * accel_factor * if data.physics.on_ground { -1.0 } else { 1.0 },
|
||||||
ori.up()
|
ori.up()
|
||||||
.cross(accel)
|
.cross(accel)
|
||||||
.try_normalized()
|
.try_normalized()
|
||||||
@ -168,6 +177,7 @@ impl CharacterBehavior for Data {
|
|||||||
update.character = CharacterState::Glide(Self {
|
update.character = CharacterState::Glide(Self {
|
||||||
ori,
|
ori,
|
||||||
last_vel: *data.vel,
|
last_vel: *data.vel,
|
||||||
|
timer: self.timer + data.dt.0,
|
||||||
..*self
|
..*self
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user