pub struct Chaser {
last_search_tgt: Option<Vec3<f32>>,
route: Option<(Route, bool, Vec3<f32>)>,
astar: Option<(Astar<Node, FxBuildHasher>, Vec3<f32>)>,
flee_from: Option<Vec3<f32>>,
path_length: PathLength,
path_state: PathState,
last_update_time: Option<Time>,
recent_states: VecDeque<(Time, Vec3<f32>, Vec3<f32>)>,
}
Expand description
A self-contained system that attempts to chase a moving target, only performing pathfinding if necessary
Fields§
§last_search_tgt: Option<Vec3<f32>>
§route: Option<(Route, bool, Vec3<f32>)>
bool
indicates whether the Route is a complete route to the target
Vec3
is the target end pos
astar: Option<(Astar<Node, FxBuildHasher>, Vec3<f32>)>
We use this hasher (FxHash) because: (1) we don’t care about DDOS attacks (We can use FxHash); (2) we want this to be constant across compiles because of hot-reloading (Ruling out AAHash);
The Vec3 is the astar’s start position.
flee_from: Option<Vec3<f32>>
§path_length: PathLength
Whether to allow consideration of longer paths, npc will stand still while doing this.
path_state: PathState
The current state of the path.
last_update_time: Option<Time>
The last time the chase
method was called.
recent_states: VecDeque<(Time, Vec3<f32>, Vec3<f32>)>
(position, requested walk dir)
Implementations§
Source§impl Chaser
impl Chaser
fn stuck_check( &mut self, pos: Vec3<f32>, bearing: Vec3<f32>, speed: f32, time: &Time, ) -> (Vec3<f32>, f32, bool)
fn reset(&mut self)
Sourcepub fn chase<V>(
&mut self,
vol: &V,
pos: Vec3<f32>,
vel: Vec3<f32>,
tgt: Vec3<f32>,
traversal_cfg: TraversalConfig,
time: &Time,
) -> Option<(Vec3<f32>, f32, bool)>
pub fn chase<V>( &mut self, vol: &V, pos: Vec3<f32>, vel: Vec3<f32>, tgt: Vec3<f32>, traversal_cfg: TraversalConfig, time: &Time, ) -> Option<(Vec3<f32>, f32, bool)>
Returns bearing and speed
Bearing is a Vec3<f32>
dictating the direction of movement
Speed is an f32 between 0.0 and 1.0
pub fn get_route(&self) -> Option<&Route>
pub fn last_target(&self) -> Option<Vec3<f32>>
pub fn state(&self) -> (PathLength, PathState)
pub fn last_update_time(&self) -> Time
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Chaser
impl RefUnwindSafe for Chaser
impl Send for Chaser
impl Sync for Chaser
impl Unpin for Chaser
impl UnwindSafe for Chaser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
Tries to create the default.
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
Calls
try_default
and panics on an error case.