feat: generalising of NPC logic
This commit is contained in:
parent
41bcf4cdf7
commit
1625a11c42
6 changed files with 74 additions and 37 deletions
|
|
@ -36,22 +36,8 @@ String WretchedPatrolState::get_next_state() const {
|
|||
return get_class();
|
||||
}
|
||||
|
||||
void WretchedChaseState::enter_state() {
|
||||
get_target()->set_movement_speed(get_target()->get_max_speed());
|
||||
get_nav()->set_max_speed(get_target()->get_max_speed());
|
||||
get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position());
|
||||
get_anim()->play("ready"); // TODO: replace this with "run"
|
||||
}
|
||||
|
||||
void WretchedChaseState::process(double delta) {
|
||||
// TODO: optimize this with some checks to avoid re-pathing every frame
|
||||
get_nav()->set_target_position(PlayerBody::get_singleton()->get_global_position());
|
||||
Vector3 const direction{ get_target()->get_global_position().direction_to(get_nav()->get_next_path_position()) };
|
||||
get_target()->set_movement_direction(Vector2{ direction.x, direction.z }.normalized());
|
||||
}
|
||||
|
||||
String WretchedChaseState::get_next_state() const {
|
||||
if (get_target()->get_global_position().distance_to(PlayerBody::get_singleton()->get_global_position()) < 2.f) {
|
||||
if (get_body()->get_global_position().distance_to(PlayerBody::get_singleton()->get_global_position()) < 2.f) {
|
||||
return WretchedAttackState::get_class_static();
|
||||
}
|
||||
return get_class();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue