aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/AISystem.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-06 10:39:18 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-06 10:39:18 +0100
commit9c2cafd85ed7aa9a860ba25fbe2bd3ccc2439f29 (patch)
tree1b0601f5867acbfe6adf2defe097f067495aedfa /src/crepe/system/AISystem.cpp
parent42ecf9c1d0e3ed1f37f99a24f31241b68f978b28 (diff)
Using Rigidbody from now on
Diffstat (limited to 'src/crepe/system/AISystem.cpp')
-rw-r--r--src/crepe/system/AISystem.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp
index 3c61c78..d496e12 100644
--- a/src/crepe/system/AISystem.cpp
+++ b/src/crepe/system/AISystem.cpp
@@ -1,4 +1,5 @@
#include "api/LoopTimer.h"
+#include "api/Rigidbody.h"
#include "api/Transform.h"
#include "manager/ComponentManager.h"
#include "manager/Mediator.h"
@@ -16,16 +17,13 @@ void AISystem::update() {
double dt = LoopTimer::get_instance().get_delta_time();
for (AI & ai : ai_components) {
+ RefVector<Rigidbody> rigidbodies
+ = mgr.get_components_by_id<Rigidbody>(ai.game_object_id);
+ Rigidbody & rigidbody = rigidbodies.front().get();
+
vec2 force = this->calculate(ai);
- vec2 acceleration = force / ai.mass;
- ai.velocity += acceleration * dt;
- ai.velocity.truncate(ai.max_speed);
-
- // Update the position
- RefVector<Transform> transforms
- = mgr.get_components_by_id<Transform>(ai.game_object_id);
- Transform & transform = transforms.front().get();
- transform.position += ai.velocity * dt;
+ vec2 acceleration = force / rigidbody.data.mass;
+ rigidbody.data.linear_velocity += acceleration * dt;
}
}
@@ -69,10 +67,12 @@ vec2 AISystem::seek(const AI & ai) {
ComponentManager & mgr = mediator.component_manager;
RefVector<Transform> transforms = mgr.get_components_by_id<Transform>(ai.game_object_id);
Transform & transform = transforms.front().get();
+ RefVector<Rigidbody> rigidbodies = mgr.get_components_by_id<Rigidbody>(ai.game_object_id);
+ Rigidbody & rigidbody = rigidbodies.front().get();
vec2 desired_velocity = ai.seek_target - transform.position;
desired_velocity.normalize();
- desired_velocity *= ai.max_speed;
+ desired_velocity *= rigidbody.data.max_linear_velocity;
- return desired_velocity - ai.velocity;
+ return desired_velocity - rigidbody.data.linear_velocity;
}