-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI_Pathfinder.cpp
More file actions
33 lines (25 loc) · 988 Bytes
/
Copy pathAI_Pathfinder.cpp
File metadata and controls
33 lines (25 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "AI_Pathfinder.h"
AI_Pathfinder::AI_Pathfinder(PathmapWorld* world, glm::vec3 start, glm::vec3 target) : WORLD_(world), START_(start), TARGET_(target) {
PATH_->search(WORLD_, START_, TARGET_);
cur_goal = PATH_->get_current_pos();
}
void AI_Pathfinder::update(GameObject& g) {
if(!PATH_->has_path() || (!PATH_->has_next() && !PATH_->has_prev())) { g.has_collision = false; return; }
if(glm::length(g.get_position() - cur_goal) <= stoppage) {
if(!PATH_->has_next() || !PATH_->has_prev()) {
forward = !forward;
}
cur_goal = (forward) ? PATH_->get_next_pos() : PATH_->get_prev_pos();
} else {
glm::vec3 pos(g.get_position());
glm::vec3 direction = glm::normalize(cur_goal - g.get_position());
g.velocity += (direction * speed); // *(glm::length(cur_goal - g.get_position()) * 10);
g.velocity *= 0.9f;
}
}
void AI_Pathfinder::receive(std::string component, std::string action) {
}
void AI_Pathfinder::activate() {
}
void AI_Pathfinder::deactivate() {
}