36 LVecBase3 direction_to_target;
40 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);
43 direction_to_target = _ai_char->get_ai_behaviors()->_seek_obj->_seek_position - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render);
45 distance = direction_to_target.length();
47 _arrival_direction = direction_to_target;
48 _arrival_direction.normalize();
50 if(
int(distance) == 0) {
51 _ai_char->_steering->_steering_force = LVecBase3(0.0, 0.0, 0.0);
52 _ai_char->_steering->_arrival_force = LVecBase3(0.0, 0.0, 0.0);
54 if(_ai_char->_steering->_seek_obj !=
nullptr) {
55 _ai_char->_steering->
turn_off(
"arrival");
56 _ai_char->_steering->
turn_on(
"arrival_activate");
59 return(LVecBase3(0.0, 0.0, 0.0));
62 _arrival_done =
false;
65 double u = _ai_char->get_velocity().length();
66 LVecBase3 desired_force = ((u * u) / (2 * distance)) * _ai_char->get_mass();
68 if(_ai_char->_steering->_seek_obj !=
nullptr) {
69 return(desired_force);
72 if(_ai_char->_steering->_pursue_obj !=
nullptr) {
74 if(distance > _arrival_distance) {
75 _ai_char->_steering->
turn_off(
"arrival");
76 _ai_char->_steering->
turn_on(
"arrival_activate");
80 return(desired_force);
83 std::cout <<
"Arrival works only with seek and pursue" << std::endl;
84 return(LVecBase3(0.0, 0.0, 0.0));
95 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));
98 dirn = (_ai_char->_ai_char_np.
get_pos(_ai_char->_window_render) - _ai_char->get_ai_behaviors()->_seek_obj->_seek_position);
100 double distance = dirn.length();
102 if(distance < _arrival_distance && _ai_char->_steering->_steering_force.length() > 0) {
103 _ai_char->_steering->
turn_off(
"arrival_activate");
104 _ai_char->_steering->
turn_on(
"arrival");
106 if(_ai_char->_steering->
is_on(_ai_char->_steering->_seek)) {
107 _ai_char->_steering->
turn_off(
"seek");
110 if(_ai_char->_steering->
is_on(_ai_char->_steering->_pursue)) {
111 _ai_char->_steering->
pause_ai(
"pursue");