swim now uses handle_orientation fn

This commit is contained in:
Adam Whitehurst 2020-03-21 07:06:35 -07:00
parent ae175e57f3
commit cb04df7736
2 changed files with 5 additions and 21 deletions

View File

@ -81,7 +81,7 @@ impl CharacterBehavior for Data {
}
};
} else {
handle_orientation(data, &mut update);
handle_orientation(data, &mut update, 10.0);
}
// Handling attacking

View File

@ -53,10 +53,10 @@ fn basic_move(data: &JoinData, update: &mut StateUpdate) {
}
}
handle_orientation(data, update);
handle_orientation(data, update, 9.0);
}
pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate) {
pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate, strength: f32) {
// Set direction based on move direction
let ori_dir = if update.character.is_attack() || update.character.is_block() {
Vec2::from(data.inputs.look_dir).normalized()
@ -69,7 +69,7 @@ pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate) {
&& (update.ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared()
> 0.001
{
update.ori.0 = vek::ops::Slerp::slerp(update.ori.0, ori_dir.into(), 9.0 * data.dt.0);
update.ori.0 = vek::ops::Slerp::slerp(update.ori.0, ori_dir.into(), strength * data.dt.0);
}
}
@ -84,23 +84,7 @@ fn swim_move(data: &JoinData, update: &mut StateUpdate) {
0.0
};
// Set direction based on move direction when on the ground
let ori_dir = if update.character.is_attack() || update.character.is_block() {
Vec2::from(data.inputs.look_dir).normalized()
} else {
Vec2::from(update.vel.0)
};
if ori_dir.magnitude_squared() > 0.0001
&& (update.ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared()
> 0.001
{
update.ori.0 = vek::ops::Slerp::slerp(
update.ori.0,
ori_dir.into(),
if data.physics.on_ground { 9.0 } else { 2.0 } * data.dt.0,
);
}
handle_orientation(data, update, if data.physics.on_ground { 9.0 } else { 2.0 });
// Force players to pulse jump button to swim up
if data.inputs.jump.is_pressed() && !data.inputs.jump.is_long_press(Duration::from_millis(600))