2 registered members (3s05bmmc, flink),
650
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Tip of the Week #10: New Pathfinding Solution!
[Re: Superku]
#437689
02/23/14 05:24
02/23/14 05:24
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
A simple function set for Bézier curve "interpolation" has been added as well as integrated directly into the pathfinding. It's not perfect (only 1 node gets interpolated/ smoothed at a time for stability reasons in the pathfinding algorithm) but the entity follows a much smoother path now and it's pretty fast, too: http://opserver.de/swik10/index.php?title=Pathfindinghttp://www.superku.de/HPF_v1.21.zip (updated) (EDIT: fixed links)
Last edited by Superku; 08/08/15 08:30.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Tip of the Week #10: New Pathfinding Solution!
[Re: Superku]
#437694
02/23/14 10:06
02/23/14 10:06
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Fixed a few pretty big bugs in the function that calculates the projection of the target position onto the region bounding box (green dot in upper screen), the pathfinding barely/ never worked on bigger areas. Please download the new version here: http://www.superku.de/HPF_v1.21.zip
Last edited by Superku; 02/23/14 14:49.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Tip of the Week #10: New Pathfinding Solution!
[Re: Superku]
#446632
10/23/14 22:24
10/23/14 22:24
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
Junior Member
|
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
This error "HPF_PATH_GET: Invalid start/ target node(s)!". How do I check the entity speed per tick? I built a level that's slightly smaller than the "test" level I downloaded with your code and I'm calling up the level from the menu in my game as if it were one of my game's levels. It only has 2 regions and a total of 18 nodes between the 2 paths, and only one AI character. So it's a small level. My game loads the player into the level, but before now, I hadn't included any NPC in the game. So I put one NPC in my test level and tried to make it so that he finds his way to whatever spot the player was standing when the "t" key was pressed. He should go to that spot even if the player has moved away from the placw. This is the code the AI is running:
action FollowPlayer()
{
while(!player)
wait(-1);
vec_for_min(AIfeet, me); //assigning the lowest position of the model to the vector named "AIfeet"
c_setminmax(my);
vec_fill(my.min_x,-24);
vec_fill(my.max_x,24);
vec_set(PlayerTarget,my.x);
my.skill10 = hpf_path_get_max_nodes(my);
my.group = 2; // ignore other enemy units when doing pathfinding and visibility calculations (with IGNORE_PUSH)
while(1)
{
if(key_t)
vec_set(PlayerTarget, vector(player.x, player.y, player.z));
my.red = 0;
my.ambient = 0;
my.lightrange = 0;
if(!key_ins) hpf_region_get_target(temp,my,PlayerTarget,HPF_XYZ); //using insert key for dummy if statement
else vec_set(temp, PlayerTarget);
hpf_path_draw(my,COLOR_GREEN);
temp.z = my.z;
if(vec_dist(temp,my.x) > 16)
{
my.red = 100;
my.ambient = 100;
my.lightrange = 100;
vec_diff(temp2,temp,my.x);
vec_to_angle(temp,temp2);
my.pan += ang(temp.x-my.pan)*0.25*time_step;
result = c_move(me,vector(maxv(10-0.1*abs(ang(temp.x-my.pan)),0)*time_step,0,0), vector(0, 0, -AIdistancedown),IGNORE_PASSABLE | GLIDE);
my.skill1 += result;
my.skill1 %= 100;
ent_animate(me,"run",my.skill1,ANM_CYCLE);
//gravity codes
if(c_trace(my.x, vector(my.x,my.y,my.z-10000), IGNORE_ME|IGNORE_PASSABLE |USE_BOX) > 0)
AIdistancedown = my.z + AIfeet.z - target.z;
else
AIdistancedown = 0;
if(AIdistancedown > 0)
AIdistancedown = clamp(AIdistancedown, 0, accelerate(mygravity, 9.8, 0.1)); //0.1 is friction, accelerate "mygravity" by 9.8
//clamp limits distance down to lower limit 0 and upper limit accelerate(mygravity, 9.8, 0.1)
else
{mygravity = 0; vec_set(AILastSolidGround,vector(my.x,my.y,my.z));}
//if Mon is on ground, set gravity to zero and store position of mon on ground
}
var i;
for(i = 1; i <= my.skill10; i++)
{
path_getnode(my,i,temp,NULL);
if(vec_to_screen(temp,camera))
{
draw_text(str_for_num(NULL,i),temp.x-9,temp.y-9,vector(50,50,50));
draw_text(str_for_num(NULL,i),temp.x-10,temp.y-10,COLOR_RED);
}
}
wait(1);
}
}
Sometimes it works perfectly. At random times, it gives this error "HPF_PATH_GET: Invalid start/ target node(s)!" On the last few attempts, the whole game would hang without an error message. I can't find any pattern to the problem because the AI finds its way to certain spots perfectly sometimes, then crashes or gives an error at other times when asked to find its way to the same spot.
|
|
|
Re: Tip of the Week #10: New Pathfinding Solution!
[Re: tolu619]
#446661
10/26/14 10:19
10/26/14 10:19
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
hpf_region_get_target() uses region_find() and some string manipulation to determine the appropriate path name. Have a look at line 529 and following:
str_clip(str_tmp,3);
str_printf(str_tmp,"path%s",_chr(str_tmp));
if(!path_set(ent,str_tmp)) error("HPF_REGION_GET_TARGET: Path to region does not exist!");
Apparently when you want to use Treg_ and Tpath_ as names you will have to adapt the number in str_clip (change it to 4). Your enemy/ NPC code looks fine to me. hpf_region_get_target() calls hpf_path_get_target() which calculates corresponding start and target nodes which are then used by a subsequent hpf_path_get() call. You could add a printf("Start: %d, Target: %d, Max_nodes: %d",(int)start_node,(int)target_node,(int)max_nodes); before the error() instruction in line 216. Try disabling hpf_path_get_target_collision (in the *.h file) temporarily, too.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|