0 Favourites

Pathfinding doesn't arrive at exact location?

  • Hello,

    So I am trying to get an object with the default Pathfinding behavior (no changes) to move over to the same location as an object but unfortunately it isn't happening. It is either moving over to the top or bottom of the object.

    Here is what is happening:

    Here is my CAPX:

    I tried to add to Buildings.X (Buildings.Width/2) so as to get it to go in the middle of the building and same for height. It didn't work out. Thing is, you see the small green square going to the top right, right? If I change the navel colored sprite (bottom one -- target sprite) to another different sprite, it goes to the top left (even if it is the same size but slightly above the current target). If I change the position to something else it might end up at the bottom right.

    Am I missing something? Or am I doing something wrong?

  • Did you check the origin point to see if it is the middle of the sprite? In the image editor. Each frame can also have different origin points as well, in case you are using multiple frames.

  • Did you check the origin point to see if it is the middle of the sprite? In the image editor. Each frame can also have different origin points as well, in case you are using multiple frames.

    It is the default origin point -- I didn't mess with it; so yes, it is in the middle. I have no animations, they are all place holder art.

  • I'm not entirely sure, but the cell size defined for your pathfinding might also affect the granularity with which the terrain is evaluated and perhaps also traveled.

    try reducing the cell size in the props of the PF behaviour, perhaps you'll get a little closer to your intended location.

    But i guess you'll just have to add another event to properly lerp the object into the exact place upon arrival.

  • I tried with a cell size of 0 and still it doesn't enter through the image and reach the center of the object. I believe the object is considered arrived once it touches the borders of the object set as "destination". I followed what you said and it works when I just use the On Arrived and change position.

    Another solution I thought of is instead of setting the destination to an object, I would set the destination to an X and Y position. Still it won't move the object till the PF object would be centered on the location, but it would be far nearer than the original general position of an object.

    Thank you very much for the help!

  • The Destination Object X,Y position is based on its Origin image point..not its border or collision box

    it would suggest that its the size of the pathfinding cell but if you are saying you entered a size of 0 then it must be something else

    An objects position is just a destination..its no different that just stating a position....both object position and screen positions are the same thing...based on image origin

    personally I would store Mouseclick.X, Y coordinates in a Global Variable and then update and send the pathfinder to those Coordinates..

    its more accurate

  • The Destination Object X,Y position is based on its Origin image point..not its border or collision box

    it would suggest that its the size of the pathfinding cell but if you are saying you entered a size of 0 then it must be something else

    An objects position is just a destination..its no different that just stating a position....both object position and screen positions are the same thing...based on image origin

    personally I would store Mouseclick.X, Y coordinates in a Global Variable and then update and send the pathfinder to those Coordinates..

    its more accurate

    I understand that sending the Mouse X and Y positions would be easier. But the intended use won't benefit from that, unfortunately. What I want is that the moving object to arrive at the dead center of another object. If I send the Mouse X and Mouse Y, that won't always equal the dead center of the object. The user might have clicked on the borders of the object for example.

  • A quick and dirty fix would be that pathfinding only works if the object ISN'T overlapping the destination object... then when it touches the destination to have it move to the X.Y position of the destination manually - since by the time it has touched the object the pathfinding has already done it's job.

    You could even create a small buffer around the destination (use a slightly enlarged version of the same sprite maybe) so that it "corrects" itself before it's already on-top. It might make this look a little less "oh um let me just fix myself at the last second".

    ~Sol

  • A quick and dirty fix would be that pathfinding only works if the object ISN'T overlapping the destination object... then when it touches the destination to have it move to the X.Y position of the destination manually - since by the time it has touched the object the pathfinding has already done it's job.

    You could even create a small buffer around the destination (use a slightly enlarged version of the same sprite maybe) so that it "corrects" itself before it's already on-top. It might make this look a little less "oh um let me just fix myself at the last second".

    ~Sol

    Currently that is what I am doing, as mentioned by Facecrime, I do a set position at the On Arrive event for now. Once I get the basic functionality going, I'll look into making it more smooth.

  • Oh my bad I didn't read your post very well it seems. Haha!

    ~Sol

  • Oh my bad I didn't read your post very well it seems. Haha!

    ~Sol

    Not at all, you confirmed that the best method is what Facecrime mentioned. I didn't like the fact that Construct 2 was doing this, but apparently no other way.

    Thanks a lot!

  • Just curious, did you try making the actual object that is using path finding very small? Maybe reduce the size to only 1 pixel? Just to see if the theory about it stops when it touches the border of the destination?

    If it's smaller, maybe it will get closer to the destination point

    *EDIT*

    I think it's obvious that I don't really ever use path finding - so these problems are new to me also!

    ~Sol

  • Just curious, did you try making the actual object that is using path finding very small? Maybe reduce the size to only 1 pixel? Just to see if the theory about it stops when it touches the border of the destination?

    If it's smaller, maybe it will get closer to the destination point

    *EDIT*

    I think it's obvious that I don't really ever use path finding - so these problems are new to me also!

    ~Sol

    The moving object is 15x15 px by default. 1x1px is almost impossible for me to see. I tried with 5x5px and it doesn't get any nearer. In fact, what I discovered that the exact position of arrival is not fixed.

    So for example, if I send instance1 of moving object to another object's position it will arrive (for example, this isn't 100% true but just to give an example) at the top left of the object (inside the object not outside of its borders).

    If I choose instance2 of the moving object from another location, it will arrive at middle left instead of top left as the first instance. Clearly the targeted position if I use a sprite as the position is messed up (perhaps a bug?) or there is something I am not understanding with path finding that is going under the hood.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • How I do it is by checking frequently for line of sight to the destination, and when the sprite has it I stop the pathfinding behavior and start the moveto plugin.

  • Maybe another way would be to create/spawn a 1pixel transparent sprite on mouse click ..then set the 1pixel sprites position to the clicked object.X,Y origin within the same event..

    -->

    Then 'find path' to the 1pixel sprite.x,y

    and destroy the 1pixel sprite after pathfinder arrives at destination

    that might work a little better

    also If you needed to find paths to moving objects then you would just add a pin behavior to the 1pixel sprite which is pinned to object at initial mouse click

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
105 16,954
Magistross's avatar
Magistross
Unread hot topic
34 2,246
KTML5's avatar
KTML5
Topic
21 474
YoHoho's avatar
YoHoho