pandemonium_engine/modules/steering_ai/behaviors/gsai_cohesion.cpp

35 lines
867 B
C++
Raw Normal View History

2023-01-13 21:29:17 +01:00
#include "gsai_cohesion.h"
2023-01-14 02:31:42 +01:00
#include "../gsai_steering_agent.h"
#include "../gsai_target_acceleration.h"
#include "../proximities/gsai_proximity.h"
2023-01-14 02:31:42 +01:00
void GSAICohesion::_calculate_steering(Ref<GSAITargetAcceleration> acceleration) {
ERR_FAIL_COND(!proximity.is_valid());
ERR_FAIL_COND(!agent.is_valid());
2023-01-14 02:31:42 +01:00
acceleration->set_zero();
_center_of_mass = Vector3();
int neighbor_count = proximity->find_neighbors(_callback);
if (neighbor_count > 0) {
_center_of_mass *= 1.0 / neighbor_count;
2023-01-14 02:31:42 +01:00
acceleration->set_linear((_center_of_mass - agent->get_position()).normalized() * agent->get_linear_acceleration_max());
}
}
2023-01-14 02:31:42 +01:00
bool GSAICohesion::_report_neighbor(Ref<GSAISteeringAgent> neighbor) {
_center_of_mass += neighbor->get_position();
return true;
}
GSAICohesion::GSAICohesion() {
}
GSAICohesion::~GSAICohesion() {
}
2023-01-14 02:31:42 +01:00
void GSAICohesion::_bind_methods() {
}