Pathfinding problem

Started by Radiant, Fri 04/06/2004 10:11:03

Previous topic - Next topic

Radiant

I have a Bad Guy (tm) 'attacking' EGO by using FollowCharacter (BADGUY, EGO, 0, 0), and doing something nasty upon touch (e.g. if AreCharsColliding).
However it seems that the pathfinding algorithm used is kind of weird. If no straight path exists the first time this function is called, it may take BADGUY a very long time to actually find EGO. Is it possible to make the pathfinder more, well, aggressive? Or should I code my own, maybe using MoveCharDirect or something?

®2-D2

try calling MoveCharacterBlocking every frame (i.e. inifinite loop) that should have a similar effect like FollowCharacter

Gilbert

I think that may reset the follower's animation every loop, making it sluggish, moreover, it should be MoveCharacterBlocking() I think.

SSH

#3
Due to the way that the collision detection works, I think it is generally best to have a restriction on your two fighters only being able to move in one dimension, otherwise, the two can be at the same x position, different y and look like they are nowhere near each other, yet if their sprites overlap you collision detection kicks in. Thus, keep movement to the x dimension only (maybe allowing a few pixels in the y) and your path problem disappears...Ã,  ;)

I've thought that to do fighting in AGS properly, you need to have a character made of of various sub-characters for arms, legs, head, body etc so that the collision detection is a bit more meaningful...

As for writing your own pathfinder, I have done a fight thing where you look at the distance from the enemy you are, if very large, move to medium range, if medium range move to close range, if close range then attack. It can mean that your character looks like they are approaching cautiously, too: stopping every now and then to re-assess (which is actaully exactly what is happeing!). It also avoids the resetting of the frame problem, as the MoveCharacter command only happens every now and then rather tahn eveyr game cycle.
12

Radiant

I think there's a difference between AreCharsCollinding and AreThingsOverlapping (the former does take Y diff into account afaik)

Pumaman

The pathfinder attempts to move as close as possible to the target co-ordinates. Sometimes, depending on the layout of the room, this can actually be a relatively long way out of reach of the target character.

With such a vague problem, I'm not really sure I can do much about it. If you'd like to upload something which demonstrates the problem, we may be able to suggest workarounds.

1eyedParrot

I ran into a similiar problem when coding the fighting engine for QFI. I did it this way-

(this function is called in the global repeatedly execute function
Code: ags

PC_Wtimer++; // walking timer
int pcxdist=character[EGO].x-character[NPC_List[PC_target]].x; // x distance
int pcydist=character[EGO].y-character[NPC_List[PC_target]].y; // y distance
if(pcxdist<0)
{pcxdist=-1*pcxdist;}
if(pcydist<0)
{pcydist=-1*pcydist;}
PC_dist=pcxdist+pcydist; //  total distance

// distConst is a constant that i use to judge proper melee combat distance
if(PC_Wtimer>=10&&PC_dist>distConst)
{
   MoveCharacter(EGO, character[NPC_List[PC_target]].x, character[NPC_List[PC_target]].y);
   PC_Wtimer=0;
}


So it just checks for EGO's x and y every 10 cycles and moves the npc there. If you try to run it every cycle then EGO will hang and not move anywhere.

SMF spam blocked by CleanTalk