Compare commits
No commits in common. "70696db134358642463cc74a004f8816abc76798" and "c05d3aa28fbb82221b8f379e3b5bd327080dd815" have entirely different histories.
70696db134
...
c05d3aa28f
Binary file not shown.
Binary file not shown.
|
@ -46,31 +46,23 @@ NavigationAgent3D *WretchedState::get_nav() const {
|
|||
return this->nav;
|
||||
}
|
||||
|
||||
void WretchedPatrolState::set_patrol_target(Vector3 path_point) {
|
||||
get_nav()->set_target_position(path_point + get_target()->get_unit_offset_3d());
|
||||
}
|
||||
|
||||
void WretchedPatrolState::enter_state() {
|
||||
this->path = get_target()->get_unit()->get_patrol_path();
|
||||
|
||||
float const max_speed{ get_unit()->get_patrol_speed() };
|
||||
get_target()->set_movement_speed(max_speed);
|
||||
get_nav()->set_max_speed(max_speed);
|
||||
if (this->path) {
|
||||
Vector3 const nav_target{ this->path->get_closest_point(get_target()->get_global_position(), &this->path_point) };
|
||||
set_patrol_target(nav_target);
|
||||
}
|
||||
get_nav()->set_target_position(nav_target);
|
||||
}
|
||||
|
||||
void WretchedPatrolState::process(double delta) {
|
||||
if (this->path) {
|
||||
if (get_nav()->is_navigation_finished()) {
|
||||
this->path_point += 1;
|
||||
set_patrol_target(this->path->point_at(this->path_point));
|
||||
get_nav()->set_target_position(this->path->point_at(this->path_point));
|
||||
}
|
||||
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 WretchedPatrolState::get_next_state() const {
|
||||
|
|
|
@ -36,7 +36,6 @@ private:
|
|||
class WretchedPatrolState : public WretchedState {
|
||||
GDCLASS(WretchedPatrolState, WretchedState);
|
||||
static void _bind_methods() {}
|
||||
void set_patrol_target(Vector3 path_point);
|
||||
|
||||
public:
|
||||
virtual void enter_state() override;
|
||||
|
|
|
@ -59,15 +59,3 @@ void EnemyBody::set_movement_speed(float value) {
|
|||
float EnemyBody::get_movement_speed() const {
|
||||
return this->movement_speed;
|
||||
}
|
||||
|
||||
void EnemyBody::set_unit_offset(Vector2 offset) {
|
||||
this->unit_offset = offset;
|
||||
}
|
||||
|
||||
Vector2 EnemyBody::get_unit_offset() const {
|
||||
return this->unit_offset;
|
||||
}
|
||||
|
||||
Vector3 EnemyBody::get_unit_offset_3d() const {
|
||||
return { this->unit_offset.x, 0, this->unit_offset.y };
|
||||
}
|
||||
|
|
|
@ -23,9 +23,6 @@ public:
|
|||
NavigationAgent3D *get_nav() const;
|
||||
void set_movement_speed(float value);
|
||||
float get_movement_speed() const;
|
||||
void set_unit_offset(Vector2 offset);
|
||||
Vector2 get_unit_offset() const;
|
||||
Vector3 get_unit_offset_3d() const;
|
||||
|
||||
private:
|
||||
float movement_speed{ 1.f };
|
||||
|
@ -34,7 +31,6 @@ private:
|
|||
StateMachine *fsm{ nullptr };
|
||||
NpcUnit *unit{ nullptr };
|
||||
NavigationAgent3D *nav{ nullptr };
|
||||
Vector2 unit_offset{ 0, 0 };
|
||||
};
|
||||
|
||||
#endif // !ENEMY_BODY_H
|
||||
|
|
|
@ -18,12 +18,9 @@ void NpcUnit::child_added(Node *node) {
|
|||
if (EnemyBody * npc{ cast_to<EnemyBody>(node) }) {
|
||||
this->npcs.push_back(npc);
|
||||
npc->set_unit(this);
|
||||
Vector3 const offset{ npc->get_global_position() - get_global_position() };
|
||||
npc->set_unit_offset({ offset.x, offset.z });
|
||||
if (PlayerDetector * detector{ cast_to<PlayerDetector>(npc->get_node(NodePath("%PlayerDetector"))) }) {
|
||||
PlayerDetector *detector{ cast_to<PlayerDetector>(npc->get_node(NodePath("%PlayerDetector"))) };
|
||||
detector->connect(PlayerDetector::sig_awareness_changed, callable_mp(this, &self_type::on_npc_awareness_changed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NpcUnit::enter_tree() {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef NPC_UNIT_H
|
||||
#define NPC_UNIT_H
|
||||
|
||||
#include "scene/3d/node_3d.h"
|
||||
#include "scene/main/node.h"
|
||||
class StateMachine;
|
||||
class EnemyBody;
|
||||
class PatrolPath;
|
||||
|
||||
class NpcUnit : public Node3D {
|
||||
GDCLASS(NpcUnit, Node3D);
|
||||
class NpcUnit : public Node {
|
||||
GDCLASS(NpcUnit, Node);
|
||||
static void _bind_methods();
|
||||
void on_npc_awareness_changed(bool seen);
|
||||
void child_added(Node *node);
|
||||
|
|
|
@ -56,4 +56,8 @@ void StateMachine::add_state(State *state) {
|
|||
if (this->current_state == nullptr) {
|
||||
this->switch_to_state(state);
|
||||
}
|
||||
print_line("states:");
|
||||
for (KeyValue<StringName, State *> kv : this->states) {
|
||||
print_line(vformat("\t\t| %s %s", kv.key, kv.value));
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -18,6 +18,7 @@ unique_name_in_owner = true
|
|||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
path_desired_distance = 0.25
|
||||
debug_enabled = true
|
||||
|
||||
[node name="PlayerDetector" type="PlayerDetector" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://5hg5eirw7v8n"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dqlqgk1veyos8" path="res://objects/enemies/enemy_wretched.tscn" id="1_l77gx"]
|
||||
|
||||
[node name="NpcUnit" type="NpcUnit"]
|
||||
|
||||
[node name="EnemyWretched" parent="." instance=ExtResource("1_l77gx")]
|
||||
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -0.9145346, 0.023195954, -0.63123465)
|
||||
|
||||
[node name="EnemyWretched2" parent="." instance=ExtResource("1_l77gx")]
|
||||
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 1.0534863, 0.023196908, -0.6773462)
|
||||
|
||||
[node name="EnemyWretched3" parent="." instance=ExtResource("1_l77gx")]
|
||||
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -0.5066114, 0.023196908, 0.93247986)
|
||||
|
||||
[node name="EnemyWretched4" parent="." instance=ExtResource("1_l77gx")]
|
||||
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 1.3384295, 0.023197861, 0.74458694)
|
Loading…
Reference in a new issue