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() {
29 if(_path.size() > 0) {
30 _curr_path_waypoint = _path.size() - 1;
32 _dummy.set_pos(_path[_curr_path_waypoint]);
33 _ai_char->_steering->
pursue(_dummy, _follow_weight);
48 if(_type==
"pathfind") {
52 if(_ai_char->_steering->_path_find_obj->_dynamic_avoid) {
56 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
58 if(_path.size() > 0) {
59 _curr_path_waypoint = _path.size() - 1;
60 _dummy.set_pos(_path[_curr_path_waypoint]);
64 _curr_path_waypoint = -1;
71 else if(_ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render)
72 != _ai_char->_steering->_path_find_obj->_prev_position) {
75 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
77 if(_path.size() > 0) {
78 _curr_path_waypoint = _path.size() - 1;
79 _dummy.set_pos(_path[_curr_path_waypoint]);
83 _curr_path_waypoint = -1;
91 if(_curr_path_waypoint > 0) {
92 double distance = (_path[_curr_path_waypoint] - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render)).length();
95 _curr_path_waypoint--;
96 _dummy.set_pos(_path[_curr_path_waypoint]);
106 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);
107 LVecBase3 _prev_position = _ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render);
108 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.
Node * find_in_mesh(NavMesh nav_mesh, LVecBase3 pos, int grid_size)
This function allows the user to pass a position and it returns the corresponding node on the navigat...
This class is used to assign the nodes on the mesh.
void do_follow()
This function allows continuous path finding by ai chars.
void add_to_path(LVecBase3 pos)
This function adds the positions generated from a pathfind or a simple path follow behavior to the _p...
void path_find(LVecBase3 pos, std::string type="normal")
This function checks for the source and target in the navigation mesh for its availability and then f...
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...
get_real_time
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last ...
LPoint3 get_pos() const
Retrieves the translation component of the transform.
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...
void start(std::string type)
This function initiates the path follow behavior.
void pursue(NodePath target_object, float pursue_wt=1.0)
This function activates pursue.