diff --git a/src/player_states.cpp b/src/player_states.cpp index 4050e30..c080cf8 100644 --- a/src/player_states.cpp +++ b/src/player_states.cpp @@ -2,6 +2,7 @@ #include "player_character.hpp" #include "tunnels_game_mode.hpp" #include "utils/game_root.hpp" +#include #include namespace godot { @@ -35,6 +36,20 @@ PlayerCharacter *PlayerState::get_manual_character() const { return this->player->get_character(); } +Vector3 PlayerState::get_home_position() const { + Basis const player_basis = this->get_manual_character()->get_global_transform().basis; + Vector3 const player_origin = this->get_manual_character()->get_global_position(); + Vector3 const offset = this->parent->get_global_position() - player_origin; + Vector3 const local = Vector3(0.f, (std::signbit(player_basis.get_column(0).dot(offset)) ? 1.f : -1.f), -1.f).normalized() * 4.f; + return player_origin + player_basis.get_column(0) * local.x + player_basis.get_column(2) * local.z; +} + +bool PlayerState::in_player_line_of_fire() const { + Transform3D const player_transform = this->get_manual_character()->get_global_transform(); + Vector3 const offset_dir = (this->parent->get_global_position() - player_transform.origin).normalized(); + return player_transform.basis.get_column(2).dot(offset_dir) >= 9.0f; +} + #undef CLASSNAME // PlayerState void FollowingPlayer::_bind_methods() { diff --git a/src/player_states.hpp b/src/player_states.hpp index c9c48a2..6ef58d8 100644 --- a/src/player_states.hpp +++ b/src/player_states.hpp @@ -18,6 +18,8 @@ public: protected: float get_distance_from_player(bool sqr = false) const; PlayerCharacter *get_manual_character() const; + Vector3 get_home_position() const; + bool in_player_line_of_fire() const; protected: PlayerCharacter *parent{nullptr}; StateMachine *state_machine{nullptr};