Pathfinding doesn't arrive at exact location?

Get help using Construct 2

Post » Wed Aug 03, 2016 5:35 am

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:
Image

Here is my CAPX:
Image

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

Post » Wed Aug 03, 2016 7:48 am

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.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,616
Reputation: 61,653

Post » Wed Aug 03, 2016 8:16 am

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

Post » Wed Aug 03, 2016 10:38 am

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.
B
13
S
6
Posts: 222
Reputation: 1,859

Post » Wed Aug 03, 2016 11:19 am

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

Post » Thu Aug 04, 2016 1:51 am

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
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 2:27 am

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

Post » Thu Aug 04, 2016 3:56 am

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

Post » Thu Aug 04, 2016 4:06 am

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

Post » Thu Aug 04, 2016 4:11 am

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

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

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests