mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Entities will now attempt to orient towards the sprite they are interacting with.
This commit is contained in:
parent
42a0dd785b
commit
9e5744f3ee
@ -55,7 +55,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.8);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
let ori_rate = self.static_data.ori_rate;
|
||||
|
||||
handle_orientation(data, &mut update, ori_rate);
|
||||
handle_orientation(data, &mut update, ori_rate, None);
|
||||
handle_move(data, &mut update, 0.4);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.4);
|
||||
|
||||
match self.stage_section {
|
||||
|
@ -56,10 +56,9 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.7);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 0.35);
|
||||
|
||||
match self.stage_section {
|
||||
StageSection::Buildup => {
|
||||
|
@ -48,7 +48,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.3);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
|
||||
match self.stage_section {
|
||||
StageSection::Buildup => {
|
||||
|
@ -72,7 +72,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.7);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, self.static_data.move_speed);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -175,7 +175,12 @@ impl CharacterBehavior for Data {
|
||||
match self.stage_section {
|
||||
StageSection::Buildup => {
|
||||
if self.timer < self.static_data.stage_data[stage_index].base_buildup_duration {
|
||||
handle_orientation(data, &mut update, 0.4 * self.static_data.ori_modifier);
|
||||
handle_orientation(
|
||||
data,
|
||||
&mut update,
|
||||
0.4 * self.static_data.ori_modifier,
|
||||
None,
|
||||
);
|
||||
|
||||
// Build up
|
||||
update.character = CharacterState::ComboMelee(Data {
|
||||
@ -289,7 +294,12 @@ impl CharacterBehavior for Data {
|
||||
});
|
||||
} else if self.timer < self.static_data.stage_data[stage_index].base_swing_duration
|
||||
{
|
||||
handle_orientation(data, &mut update, 0.4 * self.static_data.ori_modifier);
|
||||
handle_orientation(
|
||||
data,
|
||||
&mut update,
|
||||
0.4 * self.static_data.ori_modifier,
|
||||
None,
|
||||
);
|
||||
|
||||
// Forward movement
|
||||
handle_forced_movement(data, &mut update, ForcedMovement::Forward {
|
||||
@ -314,7 +324,12 @@ impl CharacterBehavior for Data {
|
||||
},
|
||||
StageSection::Recover => {
|
||||
if self.timer < self.static_data.stage_data[stage_index].base_recover_duration {
|
||||
handle_orientation(data, &mut update, 0.8 * self.static_data.ori_modifier);
|
||||
handle_orientation(
|
||||
data,
|
||||
&mut update,
|
||||
0.8 * self.static_data.ori_modifier,
|
||||
None,
|
||||
);
|
||||
// Recovers
|
||||
update.character = CharacterState::ComboMelee(Data {
|
||||
static_data: self.static_data.clone(),
|
||||
|
@ -82,7 +82,7 @@ impl CharacterBehavior for Data {
|
||||
match self.stage_section {
|
||||
StageSection::Buildup => {
|
||||
if self.timer < self.static_data.buildup_duration {
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
// Build up
|
||||
update.character = CharacterState::DashMelee(Data {
|
||||
timer: tick_attack_or_default(data, self.timer, None),
|
||||
@ -109,7 +109,7 @@ impl CharacterBehavior for Data {
|
||||
/ self.static_data.charge_duration.as_secs_f32())
|
||||
.min(1.0);
|
||||
|
||||
handle_orientation(data, &mut update, self.static_data.ori_modifier);
|
||||
handle_orientation(data, &mut update, self.static_data.ori_modifier, None);
|
||||
handle_forced_movement(data, &mut update, ForcedMovement::Forward {
|
||||
strength: self.static_data.forward_speed * charge_frac.sqrt(),
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 1.0);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -35,7 +35,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 1.0);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
handle_dodge_input(data, &mut update);
|
||||
|
@ -10,7 +10,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 1.0);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
handle_wield(data, &mut update);
|
||||
|
@ -60,7 +60,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.3);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
|
||||
|
@ -54,7 +54,7 @@ pub struct Data {
|
||||
impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.3);
|
||||
|
||||
match self.stage_section {
|
||||
|
@ -54,7 +54,7 @@ impl CharacterBehavior for Data {
|
||||
update.should_strafe = false;
|
||||
|
||||
// Smooth orientation
|
||||
handle_orientation(data, &mut update, 2.5);
|
||||
handle_orientation(data, &mut update, 2.5, None);
|
||||
|
||||
match self.stage_section {
|
||||
StageSection::Buildup => {
|
||||
|
@ -65,7 +65,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, self.static_data.move_efficiency);
|
||||
|
||||
match self.stage_section {
|
||||
|
@ -10,7 +10,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 0.4);
|
||||
handle_jump(data, &mut update, 1.0);
|
||||
handle_wield(data, &mut update);
|
||||
|
@ -4,6 +4,7 @@ use crate::{
|
||||
event::ServerEvent,
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
terrain::SpriteKind,
|
||||
util::Dir,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
@ -43,7 +44,10 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 0.0);
|
||||
let ori_dir = Dir::from_unnormalized(Vec3::from(
|
||||
(self.static_data.sprite_pos.map(|x| x as f32) - data.pos.0).xy(),
|
||||
));
|
||||
handle_orientation(data, &mut update, 1.0, ori_dir);
|
||||
handle_move(data, &mut update, 0.0);
|
||||
|
||||
match self.stage_section {
|
||||
|
@ -36,7 +36,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, self.static_data.movement_speed);
|
||||
|
||||
match self.stage_section {
|
||||
|
@ -15,7 +15,7 @@ impl CharacterBehavior for Data {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_wield(data, &mut update);
|
||||
handle_orientation(data, &mut update, TURN_RATE);
|
||||
handle_orientation(data, &mut update, TURN_RATE, None);
|
||||
|
||||
update
|
||||
}
|
||||
|
@ -52,11 +52,11 @@ impl CharacterBehavior for Data {
|
||||
|
||||
match self.static_data.item_kind {
|
||||
ItemUseKind::Consumable(ConsumableKind::Drink) => {
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 1.0);
|
||||
},
|
||||
ItemUseKind::Consumable(ConsumableKind::Food | ConsumableKind::ComplexFood) => {
|
||||
handle_orientation(data, &mut update, 0.0);
|
||||
handle_orientation(data, &mut update, 0.0, None);
|
||||
handle_move(data, &mut update, 0.0);
|
||||
},
|
||||
}
|
||||
|
@ -349,11 +349,18 @@ pub fn handle_forced_movement(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_orientation(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32) {
|
||||
let dir = (is_strafing(data, update) || update.character.is_attack())
|
||||
.then(|| data.inputs.look_dir.to_horizontal().unwrap_or_default())
|
||||
.or_else(|| Dir::from_unnormalized(data.inputs.move_dir.into()))
|
||||
.unwrap_or_else(|| data.ori.to_horizontal().look_dir());
|
||||
pub fn handle_orientation(
|
||||
data: &JoinData<'_>,
|
||||
update: &mut StateUpdate,
|
||||
efficiency: f32,
|
||||
dir_override: Option<Dir>,
|
||||
) {
|
||||
let dir = dir_override.unwrap_or_else(||
|
||||
(is_strafing(data, update) || update.character.is_attack())
|
||||
.then(|| data.inputs.look_dir.to_horizontal().unwrap_or_default())
|
||||
.or_else(|| Dir::from_unnormalized(data.inputs.move_dir.into()))
|
||||
.unwrap_or_else(|| data.ori.to_horizontal().look_dir()),
|
||||
);
|
||||
let rate = {
|
||||
let angle = update.ori.look_dir().angle_between(*dir);
|
||||
data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle
|
||||
@ -422,7 +429,7 @@ pub fn fly_move(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32)
|
||||
let thrust = efficiency * force;
|
||||
let accel = thrust / data.mass.0;
|
||||
|
||||
handle_orientation(data, update, efficiency);
|
||||
handle_orientation(data, update, efficiency, None);
|
||||
|
||||
// Elevation control
|
||||
match data.body {
|
||||
|
@ -13,7 +13,7 @@ impl CharacterBehavior for Data {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
|
||||
handle_orientation(data, &mut update, 1.0);
|
||||
handle_orientation(data, &mut update, 1.0, None);
|
||||
handle_move(data, &mut update, 1.0);
|
||||
handle_climb(data, &mut update);
|
||||
attempt_input(data, &mut update);
|
||||
|
Loading…
Reference in New Issue
Block a user