How do I make path finding pick a nearest/furthest target?

Get help using Construct 2

Post » Thu Sep 25, 2014 5:37 am

Lets say I have some villagers spawning from a boat and I want them to find a path to the furthest forest to gather wood and then find a path to the nearest plot to build.

How would I have them pick nearest or furthest before setting a path?

This could also be used when fighting things trying to attack the village. I would like to limit the villagers to attach the nearest enemy.

Any thoughts?

Thank you!
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Thu Sep 25, 2014 5:46 am

add event, choose the forest sprite, look for "pick nearest/furthest"
then for the action, find the path.
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Thu Sep 25, 2014 5:40 pm

spacedoubt wrote:add event, choose the forest sprite, look for "pick nearest/furthest"
then for the action, find the path.


Sometimes I assume the goal is so unobtainable I end up overthinking how to get there. Thank you, let me try it later today and I'll get back to you!

:D
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Thu Sep 25, 2014 11:23 pm

spacedoubt wrote:add event, choose the forest sprite, look for "pick nearest/furthest"
then for the action, find the path.


This actually isn't working. I found that I can pick nearest/furthest with the path finding object but then I need to tell it where to set the path once it's picked the nearest and during this phase I can't tell it to go to the "picked" object.

Can you upload a CAPX?
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Thu Sep 25, 2014 11:56 pm

@TheSynan Are you picking nearest/furthest the forest, or the pathfinding villagers?

I opened up the pathfinding example and put in an event which went something like this:
obstacle (not pathfinding object) pick furthest to obstacle.x, obstacle.y
then for the action I had sprite (pathfinding object) find path to obstacle.x, obstacle.y

This works (I did have to delete the obstacles off to the side, it couldn't find a path to them for some reason, but that's irrelevant unless you want to replicate it in the pathfinding example...)

so replace "obstacle" with "forest" and "sprite" with your villagers and it should work.

EDIT: No wait, I confused that... it should go:
obstacle, pick furthest to SPRITE.X, SPRITE.Y (not obstacle.x and y as I said above)..
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Fri Sep 26, 2014 1:24 am

spacedoubt wrote:@TheSynan Are you picking nearest/furthest the forest, or the pathfinding villagers?

I opened up the pathfinding example and put in an event which went something like this:
obstacle (not pathfinding object) pick furthest to obstacle.x, obstacle.y
then for the action I had sprite (pathfinding object) find path to obstacle.x, obstacle.y

This works (I did have to delete the obstacles off to the side, it couldn't find a path to them for some reason, but that's irrelevant unless you want to replicate it in the pathfinding example...)

so replace "obstacle" with "forest" and "sprite" with your villagers and it should work.

EDIT: No wait, I confused that... it should go:
obstacle, pick furthest to SPRITE.X, SPRITE.Y (not obstacle.x and y as I said above)..



Thank you!
It works. I had a hell of a time with instance variables and having the "villagers" find a new path but I got it working. Thank you!

Now on to working out LOS crap haha.
B
12
S
4
G
2
Posts: 132
Reputation: 1,749


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, tarek2 and 11 guests