Pathfinding doesn't arrive at exact location?

Get help using Construct 2

Post » Thu Aug 04, 2016 4:14 am

SoldjahBoy wrote: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!
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Thu Aug 04, 2016 4:23 am

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Thu Aug 04, 2016 4:38 am

SoldjahBoy wrote: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.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Thu Aug 04, 2016 5:04 am

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.
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Thu Aug 04, 2016 5:44 am

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
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Thu Aug 04, 2016 7:07 am

Arima wrote: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.


I didn't think of that, but I am currently using the On Arrive event to then kick in the Move To command (previously was a Set Position). It looks slightly instant, which might give the feeling of "snapping". It isn't too bad though and might actually fly by as a feature.

mystazsea wrote: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


It is a stationary object that I am moving towards. This might actually work, albeit I feel this is more of a bug in Construct 2 (r229 is what I am using) more than anything else. I doubt the intended use of "Find a path to an object's X and Y position" would just end when it reaches the general abouts of the X and Y.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Fri Aug 05, 2016 2:13 pm

What happens if you set the pathfinding cell size to be the exact same as the actual object doing the pathfinding?

Eg. if your object is still set at 5px, make the path cells to be 5px also... just wondering what would cause it to suddenly stop when it gets "close enough". It has to be something between the actual object bounding box size, and the pathfinding cell size.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Aug 05, 2016 2:21 pm

SoldjahBoy wrote:What happens if you set the pathfinding cell size to be the exact same as the actual object doing the pathfinding?

Eg. if your object is still set at 5px, make the path cells to be 5px also... just wondering what would cause it to suddenly stop when it gets "close enough". It has to be something between the actual object bounding box size, and the pathfinding cell size.

~Sol


There is nothing on the layout between the two. I only have 3 objects on the layout as you can see below; the moving object is created on run time and immediately moves to one of the two objects (that have the green object). The moving object is created on the cyan/light blue square.

Image

The result above is when I increased the cell size to the same as the object moving. As you can see, not much difference.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Fri Aug 05, 2016 3:03 pm

Hmmm, this must be a "quirk" of the pathfinder movement - it just gives up when it's "good enough". Probably to do with speed/optimisation of the behaviour most likely.

I guess doing something like Arima suggested, using LOS and then simply "moveto" once LOS has been achieved. You can set your LOS distance to be fairly close to the object itself and it should give the desired result.

I think maybe I should play around with pathfinding a bit more and see if there is some other way, but that method sounds pretty good to me in theory.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Aug 05, 2016 3:21 pm

SoldjahBoy wrote:Hmmm, this must be a "quirk" of the pathfinder movement - it just gives up when it's "good enough". Probably to do with speed/optimisation of the behaviour most likely.

I guess doing something like Arima suggested, using LOS and then simply "moveto" once LOS has been achieved. You can set your LOS distance to be fairly close to the object itself and it should give the desired result.

I think maybe I should play around with pathfinding a bit more and see if there is some other way, but that method sounds pretty good to me in theory.

~Sol


Should I file a bug report or anything of the sort so Ashley could check it?

Right now I am using a check with distance() and having the Move To take over as I feel LOS is a bit of an over kill, but I might actually end up using it as you mentioned since it may make the movement appear more "fluid".
B
19
S
7
Posts: 161
Reputation: 1,751

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Kyu and 25 guests