mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added simple distance check for sprite interaction.
This commit is contained in:
parent
018f9ae53f
commit
21f75f31a2
@ -1,5 +1,5 @@
|
|||||||
// The limit on distance between the entity and a collectible (squared)
|
// The limit on distance between the entity and a collectible (squared)
|
||||||
pub const MAX_PICKUP_RANGE: f32 = 8.0;
|
pub const MAX_PICKUP_RANGE: f32 = 5.0;
|
||||||
pub const MAX_MOUNT_RANGE: f32 = 14.0;
|
pub const MAX_MOUNT_RANGE: f32 = 14.0;
|
||||||
|
|
||||||
pub const GRAVITY: f32 = 25.0;
|
pub const GRAVITY: f32 = 25.0;
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
theropod, Body, CharacterAbility, CharacterState, Density, InputAttr, InputKind,
|
theropod, Body, CharacterAbility, CharacterState, Density, InputAttr, InputKind,
|
||||||
InventoryAction, StateUpdate,
|
InventoryAction, StateUpdate,
|
||||||
},
|
},
|
||||||
consts::{FRIC_GROUND, GRAVITY},
|
consts::{FRIC_GROUND, GRAVITY, MAX_PICKUP_RANGE},
|
||||||
event::{LocalEvent, ServerEvent},
|
event::{LocalEvent, ServerEvent},
|
||||||
states::{behavior::JoinData, *},
|
states::{behavior::JoinData, *},
|
||||||
util::Dir,
|
util::Dir,
|
||||||
@ -355,12 +355,12 @@ pub fn handle_orientation(
|
|||||||
efficiency: f32,
|
efficiency: f32,
|
||||||
dir_override: Option<Dir>,
|
dir_override: Option<Dir>,
|
||||||
) {
|
) {
|
||||||
let dir = dir_override.unwrap_or_else(||
|
let dir = dir_override.unwrap_or_else(|| {
|
||||||
(is_strafing(data, update) || update.character.is_attack())
|
(is_strafing(data, update) || update.character.is_attack())
|
||||||
.then(|| data.inputs.look_dir.to_horizontal().unwrap_or_default())
|
.then(|| data.inputs.look_dir.to_horizontal().unwrap_or_default())
|
||||||
.or_else(|| Dir::from_unnormalized(data.inputs.move_dir.into()))
|
.or_else(|| Dir::from_unnormalized(data.inputs.move_dir.into()))
|
||||||
.unwrap_or_else(|| data.ori.to_horizontal().look_dir()),
|
.unwrap_or_else(|| data.ori.to_horizontal().look_dir())
|
||||||
);
|
});
|
||||||
let rate = {
|
let rate = {
|
||||||
let angle = update.ori.look_dir().angle_between(*dir);
|
let angle = update.ori.look_dir().angle_between(*dir);
|
||||||
data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle
|
data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle
|
||||||
@ -626,12 +626,22 @@ pub fn handle_manipulate_loadout(
|
|||||||
.push_front(ServerEvent::InventoryManip(data.entity, inv_action.into()));
|
.push_front(ServerEvent::InventoryManip(data.entity, inv_action.into()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
InventoryAction::Collect(pos) => {
|
InventoryAction::Collect(sprite_pos) => {
|
||||||
|
// CLosure to check if distance between a point and the sprite is less than
|
||||||
|
// MAX_PICKUP_RANGE
|
||||||
|
let sprite_range_check = |pos: Vec3<f32>| {
|
||||||
|
(sprite_pos.map(|x| x as f32) - pos).magnitude_squared()
|
||||||
|
< MAX_PICKUP_RANGE.powi(2)
|
||||||
|
};
|
||||||
|
// Checks if player's feet or head is near to sprite
|
||||||
|
let close_to_sprite = sprite_range_check(data.pos.0)
|
||||||
|
|| sprite_range_check(data.pos.0 + Vec3::new(0.0, 0.0, data.body.height()));
|
||||||
|
if close_to_sprite {
|
||||||
// First, get sprite data for position, if there is a sprite
|
// First, get sprite data for position, if there is a sprite
|
||||||
use sprite_interact::SpriteInteractKind;
|
use sprite_interact::SpriteInteractKind;
|
||||||
let sprite_at_pos = data
|
let sprite_at_pos = data
|
||||||
.terrain
|
.terrain
|
||||||
.get(pos)
|
.get(sprite_pos)
|
||||||
.ok()
|
.ok()
|
||||||
.copied()
|
.copied()
|
||||||
.and_then(|b| b.get_sprite());
|
.and_then(|b| b.get_sprite());
|
||||||
@ -652,7 +662,7 @@ pub fn handle_manipulate_loadout(
|
|||||||
buildup_duration,
|
buildup_duration,
|
||||||
use_duration,
|
use_duration,
|
||||||
recover_duration,
|
recover_duration,
|
||||||
sprite_pos: pos,
|
sprite_pos,
|
||||||
sprite_kind: sprite_interact,
|
sprite_kind: sprite_interact,
|
||||||
was_wielded: matches!(data.character, CharacterState::Wielding),
|
was_wielded: matches!(data.character, CharacterState::Wielding),
|
||||||
was_sneak: matches!(data.character, CharacterState::Sneak),
|
was_sneak: matches!(data.character, CharacterState::Sneak),
|
||||||
@ -666,6 +676,7 @@ pub fn handle_manipulate_loadout(
|
|||||||
.server_events
|
.server_events
|
||||||
.push_front(ServerEvent::InventoryManip(data.entity, inv_action.into()));
|
.push_front(ServerEvent::InventoryManip(data.entity, inv_action.into()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
// Else just do event instantaneously
|
// Else just do event instantaneously
|
||||||
|
Loading…
x
Reference in New Issue
Block a user