aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/AISystem.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-10 17:52:46 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-10 17:52:46 +0100
commit543dc375228b520605bb099bc95a23918f75e9f8 (patch)
tree627f14f37b68bc4009001ee659f9fba87be9010a /src/crepe/system/AISystem.cpp
parent6fc38e15e4b88d480d5fcb69eec36f7d8685e853 (diff)
Implemented feedback
Diffstat (limited to 'src/crepe/system/AISystem.cpp')
-rw-r--r--src/crepe/system/AISystem.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp
index d1ebeb5..e2e36a5 100644
--- a/src/crepe/system/AISystem.cpp
+++ b/src/crepe/system/AISystem.cpp
@@ -30,6 +30,9 @@ void AISystem::update() {
"AI component must be attached to a GameObject with a Rigidbody component");
}
Rigidbody & rigidbody = rigidbodies.front().get();
+ if (!rigidbody.active) {
+ continue;
+ }
if (rigidbody.data.mass <= 0) {
throw std::runtime_error("Mass must be greater than 0");
}
@@ -52,28 +55,28 @@ vec2 AISystem::calculate(AI & ai, const Rigidbody & rigidbody) {
vec2 force;
// Run all the behaviors that are on, and stop if the force gets too high
- if (ai.on(AI::BehaviorType::FLEE)) {
+ if (ai.on(AI::BehaviorTypeMask::FLEE)) {
vec2 force_to_add = this->flee(ai, rigidbody, transform);
if (!this->accumulate_force(ai, force, force_to_add)) {
return force;
}
}
- if (ai.on(AI::BehaviorType::ARRIVE)) {
+ if (ai.on(AI::BehaviorTypeMask::ARRIVE)) {
vec2 force_to_add = this->arrive(ai, rigidbody, transform);
if (!this->accumulate_force(ai, force, force_to_add)) {
return force;
}
}
- if (ai.on(AI::BehaviorType::SEEK)) {
+ if (ai.on(AI::BehaviorTypeMask::SEEK)) {
vec2 force_to_add = this->seek(ai, rigidbody, transform);
if (!this->accumulate_force(ai, force, force_to_add)) {
return force;
}
}
- if (ai.on(AI::BehaviorType::PATH_FOLLOW)) {
+ if (ai.on(AI::BehaviorTypeMask::PATH_FOLLOW)) {
vec2 force_to_add = this->path_follow(ai, rigidbody, transform);
if (!this->accumulate_force(ai, force, force_to_add)) {
@@ -132,7 +135,7 @@ vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody,
vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody,
const Transform & transform) const {
// Calculate the desired velocity (taking into account the deceleration rate)
- vec2 to_target = ai.seek_target - transform.position;
+ vec2 to_target = ai.arrive_target - transform.position;
float distance = to_target.length();
if (distance > 0.0f) {
if (ai.arrive_deceleration <= 0.0f) {
@@ -161,6 +164,7 @@ vec2 AISystem::path_follow(AI & ai, const Rigidbody & rigidbody, const Transform
if (to_target.length_squared() > ai.path_node_distance * ai.path_node_distance) {
// If the entity is not close enough to the target node, seek it
ai.seek_target = target;
+ ai.arrive_target = target;
} else {
// If the entity is close enough to the target node, move to the next node
ai.path_index++;