aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/AISystem.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-13 08:17:16 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-13 08:17:16 +0100
commit2793e8be0e6c44bb34a25522e1e75ed8a2868b32 (patch)
tree7e94ba52ac68fc42072f41dc9f19b900b0b7a345 /src/crepe/system/AISystem.cpp
parent193d5bf4d9577e63202cec45b21ed85a76a89f09 (diff)
parentfd403d038b017ec8976023471073329896035e36 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/inputSystem
Diffstat (limited to 'src/crepe/system/AISystem.cpp')
-rw-r--r--src/crepe/system/AISystem.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp
index d231c7c..680dbb8 100644
--- a/src/crepe/system/AISystem.cpp
+++ b/src/crepe/system/AISystem.cpp
@@ -13,12 +13,10 @@ using namespace std::chrono;
void AISystem::update() {
const Mediator & mediator = this->mediator;
ComponentManager & mgr = mediator.component_manager;
- LoopTimerManager & timer = mediator.loop_timer;
- RefVector<AI> ai_components = mgr.get_components_by_type<AI>();
LoopTimerManager & loop_timer = mediator.loop_timer;
+ RefVector<AI> ai_components = mgr.get_components_by_type<AI>();
- //TODO: Use fixed loop dt (this is not available at master at the moment)
- duration_t dt = loop_timer.get_delta_time();
+ float dt = loop_timer.get_scaled_fixed_delta_time().count();
// Loop through all AI components
for (AI & ai : ai_components) {
@@ -45,7 +43,7 @@ void AISystem::update() {
// Calculate the acceleration (using the above calculated force)
vec2 acceleration = force / rigidbody.data.mass;
// Finally, update Rigidbody's velocity
- rigidbody.data.linear_velocity += acceleration * duration_cast<seconds>(dt).count();
+ rigidbody.data.linear_velocity += acceleration * dt;
}
}
@@ -146,7 +144,7 @@ vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody,
}
float speed = distance / ai.arrive_deceleration;
- speed = std::min(speed, rigidbody.data.max_linear_velocity.length());
+ speed = std::min(speed, rigidbody.data.max_linear_velocity);
vec2 desired_velocity = to_target * (speed / distance);
return desired_velocity - rigidbody.data.linear_velocity;