16 Arrival::Arrival(
AICharacter *ai_ch,
double distance) {
19 _arrival_distance = distance;
20 _arrival_done =
false;
33 LVecBase3 direction_to_target;
37 direction_to_target = _ai_char->get_ai_behaviors()->_pursue_obj->_pursue_target.
get_pos(_ai_char->_window_render) - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render);
40 direction_to_target = _ai_char->get_ai_behaviors()->_seek_obj->_seek_position - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render);
42 distance = direction_to_target.length();
44 _arrival_direction = direction_to_target;
45 _arrival_direction.normalize();
47 if(
int(distance) == 0) {
48 _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
49 _ai_char->_steering->_arrival_force = LVecBase3(0.0, 0.0, 0.0);
51 if(_ai_char->_steering->_seek_obj !=
nullptr) {
52 _ai_char->_steering->
turn_off(
"arrival");
53 _ai_char->_steering->
turn_on(
"arrival_activate");
56 return(LVecBase3(0.0, 0.0, 0.0));
59 _arrival_done =
false;
62 double u = _ai_char->get_velocity().length();
63 LVecBase3 desired_force = ((u * u) / (2 * distance)) * _ai_char->get_mass();
65 if(_ai_char->_steering->_seek_obj !=
nullptr) {
66 return(desired_force);
69 if(_ai_char->_steering->_pursue_obj !=
nullptr) {
71 if(distance > _arrival_distance) {
72 _ai_char->_steering->
turn_off(
"arrival");
73 _ai_char->_steering->
turn_on(
"arrival_activate");
77 return(desired_force);
80 std::cout <<
"Arrival works only with seek and pursue" << std::endl;
81 return(LVecBase3(0.0, 0.0, 0.0));
92 dirn = (_ai_char->_ai_char_np.
get_pos(_ai_char->_window_render) - _ai_char->get_ai_behaviors()->_pursue_obj->_pursue_target.
get_pos(_ai_char->_window_render));
95 dirn = (_ai_char->_ai_char_np.
get_pos(_ai_char->_window_render) - _ai_char->get_ai_behaviors()->_seek_obj->_seek_position);
97 double distance = dirn.length();
99 if(distance < _arrival_distance && _ai_char->_steering->_steering_force.length() > 0) {
100 _ai_char->_steering->
turn_off(
"arrival_activate");
101 _ai_char->_steering->
turn_on(
"arrival");
103 if(_ai_char->_steering->
is_on(_ai_char->_steering->_seek)) {
104 _ai_char->_steering->
turn_off(
"seek");
107 if(_ai_char->_steering->
is_on(_ai_char->_steering->_pursue)) {
108 _ai_char->_steering->
pause_ai(
"pursue");
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void resume_ai(std::string ai_type)
This function resumes individual or all the AIs.
void turn_on(std::string ai_type)
This function turns on any aiBehavior which is passed as a string.
void turn_off(std::string ai_type)
This function turns off any aiBehavior which is passed as a string.
LVecBase3 do_arrival()
This function performs the arrival and returns an arrival force which is used in the calculate_priori...
void pause_ai(std::string ai_type)
This function pauses individual or all the AIs.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
bool is_on(_behavior_type bt)
This function returns true if an aiBehavior is on.
void arrival_activate()
This function checks for whether the target is within the arrival distance.