14 #include "pathFollow.h"
18 PathFollow::PathFollow(
AICharacter *ai_ch,
float follow_wt) {
19 _follow_weight = follow_wt;
20 _curr_path_waypoint = -1;
26 PathFollow::~PathFollow() {
43 if(_path.size() > 0) {
44 _curr_path_waypoint = _path.size() - 1;
46 _dummy.set_pos(_path[_curr_path_waypoint]);
47 _ai_char->_steering->
pursue(_dummy, _follow_weight);
62 if(_type==
"pathfind") {
66 if(_ai_char->_steering->_path_find_obj->_dynamic_avoid) {
70 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
72 if(_path.size() > 0) {
73 _curr_path_waypoint = _path.size() - 1;
74 _dummy.set_pos(_path[_curr_path_waypoint]);
78 _curr_path_waypoint = -1;
85 else if(_ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render)
86 != _ai_char->_steering->_path_find_obj->_prev_position) {
89 _ai_char->_steering->_path_find_obj->
path_find(_ai_char->_steering->_path_find_obj->_path_find_target);
91 if(_path.size() > 0) {
92 _curr_path_waypoint = _path.size() - 1;
93 _dummy.set_pos(_path[_curr_path_waypoint]);
97 _curr_path_waypoint = -1;
105 if(_curr_path_waypoint > 0) {
106 double distance = (_path[_curr_path_waypoint] - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render)).length();
109 _curr_path_waypoint--;
110 _dummy.set_pos(_path[_curr_path_waypoint]);
120 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);
121 LVecBase3 _prev_position = _ai_char->_steering->_path_find_obj->_path_find_target.
get_pos(_ai_char->_window_render);
122 Node* dst =
find_in_mesh(_ai_char->_steering->_path_find_obj->_nav_mesh, _prev_position, _ai_char->_steering->_path_find_obj->_grid_size);
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...
void pursue(NodePath target_object, float pursue_wt=1.0)
This function activates pursue.
get_real_time
Returns the actual number of seconds elapsed since the ClockObject was created, or since it was last ...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
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...
This class is used to assign the nodes on the mesh.
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...
void do_dynamic_avoid()
This function does the updation of the collisions to the mesh based on the new positions of the obsta...
void do_follow()
This function allows continuous path finding by ai chars.
void start(std::string type)
This function initiates the path follow behavior.
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 add_to_path(LVecBase3 pos)
This function adds the positions generated from a pathfind or a simple path follow behavior to the _p...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.