2 #include "pathFollow.h"
4 PathFollow::PathFollow(
AICharacter *ai_ch,
float follow_wt) {
5 _follow_weight = follow_wt;
6 _curr_path_waypoint = -1;
12 PathFollow::~PathFollow() {
37 if(_path.size() > 0) {
38 _curr_path_waypoint = _path.size() - 1;
40 _dummy.
set_pos(_path[_curr_path_waypoint]);
41 _ai_char->_steering->
pursue(_dummy, _follow_weight);
61 if(_type==
"pathfind") {
64 if(_ai_char->_steering->_path_find_obj->_dynamic_avoid) {
68 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
70 if(_path.size() > 0) {
71 _curr_path_waypoint = _path.size() - 1;
72 _dummy.
set_pos(_path[_curr_path_waypoint]);
76 _curr_path_waypoint = -1;
82 else if(_ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render)
83 != _ai_char->_steering->_path_find_obj->_prev_position) {
86 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
88 if(_path.size() > 0) {
89 _curr_path_waypoint = _path.size() - 1;
90 _dummy.
set_pos(_path[_curr_path_waypoint]);
94 _curr_path_waypoint = -1;
102 if(_curr_path_waypoint > 0) {
103 double distance = (_path[_curr_path_waypoint] - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render)).length();
106 _curr_path_waypoint--;
107 _dummy.
set_pos(_path[_curr_path_waypoint]);
121 Node* src = find_in_mesh(_ai_char->_steering->_path_find_obj->_nav_mesh, _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render), _ai_char->_steering->_path_find_obj->_grid_size);
122 LVecBase3 _prev_position = _ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render);
123 Node* dst = find_in_mesh(_ai_char->_steering->_path_find_obj->_nav_mesh, _prev_position, _ai_char->_steering->_path_find_obj->_grid_size);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This is the base class for all three-component vectors and points.
This class is used to assign the nodes on the mesh.
void start(string type)
This function initiates the path follow behavior.
void do_follow()
This function allows continuous path finding by ai chars.
void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the translation component of the transform, leaving rotation and scale untouched.
void add_to_path(LVecBase3 pos)
This function adds the positions generated from a pathfind or a simple path follow behavior to the _p...
LPoint3 get_pos() const
Retrieves the translation component of the transform.
void path_find(LVecBase3 pos, string type="normal")
This function checks for the source and target in the navigation mesh for its availability and then f...
bool check_if_possible()
This function checks if the current positions of the ai char and the target char can be used to gener...
void do_dynamic_avoid()
This function does the updation of the collisions to the mesh based on the new positions of the obsta...
double get_real_time() const
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last ...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
void pursue(NodePath target_object, float pursue_wt=1.0)
This function activates pursue.