[Behavior]PathFinder

Post your completed addons to share with the community

Post » Wed Mar 28, 2012 12:25 am

@yumarod3: I can't get the file it's asking me to signup or login.
Try to upload it on dropbox, it's far fairer to share files.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Mar 28, 2012 12:44 am

I updated the link into Dropbox :)
B
6
Posts: 14
Reputation: 478

Post » Wed Mar 28, 2012 2:04 am

@yumarod3: Ok I saw it.
It's a "bug" in the moving example, not the plugin itself.
That's also why the conditions "On path generated" and "on path failed" exist, so that the developper handle the behavior of their application according to the result of the generation.

If there's no path, there's no need for the object to be set to moving.

Anyway the examples are provided as it, as an illustration of how to use the PF.
They need to be adapted for each usage, not be simply ripped of.

You found yourself a possible implementation with the branch plugin, as I said earlier, you could simply use the "on path generation" conditions. In one case setting the move variable to 1 as expected and to 0 in the other case.

The PF itself only deals with finding/generating a path.
The movement is up to the developper as there could be thousands of ways and expectations on how should the object move.

BTW I believe there were automated movement behaviors that were released since the first release of the PF that could handle the movement easier, it needs a bit of browsing in the plugins list I think.Kyatric2012-03-28 02:06:21
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Sat May 19, 2012 10:56 pm

@Yann
Hi Yann, thanks for the great example you've provided! I understand some of it, but I don't quite get the following action:

Lerp(Sprite.PathFinder.getCtXPathList(max(0,floor(iteration)-1)),Sprite.PathFinder.getCtXPathList(floor(iteration)),iteration-floor(iteration))

Would you mind breaking it down for me? Sorry I might need the dumbed down explanation :)
B
34
S
8
G
3
Posts: 328
Reputation: 7,692

Post » Sun May 20, 2012 2:40 pm

Basically, once the path is generated, the list of coordinate to go through is stored in an array you can query via getCtXPathList(n) and getCtYPathList(n), n is just the index of the cells listed. It goes from 0 (starting cell) to the the number of cell to travel-1 (the last cell).

But it's just coordinates, if you simply read the array and change the position of the sprite accordingly, you will have a stepped movement.

Lerp(a,b,t) = a + (b-a) * t
so basically if t evolve from 0 to 1 you get a nice interpolation from a to b.

Here I use lerp() to go from index n (a) to index n+1 (b) in the array.
The global variable iteration simply count time since the start of the interpolation.
t = iteration-floor(iteration) means that I only keep the decimal part.
t = 5.2 - floor(5.2) = 5.2-5 = 0.2

So for example, if you are at iteration = 5.5 seconds
You will get something like
Lerp(getCtXPathList(4),getCtXPathList(5),0.5)
Which means you'll be halfway between the X coordinate at n=4 and n=5.

Which also means that if you choose the cut corner option, you'll go faster in diagonal than in orthogonal movements.

This formula can be enhanced by taking into account the distance. But it should be handle at the 'iteration' incrementation. With something like
Code: Select all
set length to distance(getCtXPathList(max(0,floor(iteration)-1)),getCtYPathList(max(0,floor(iteration)-1)),getCtXPathList(floor(iteration)),getCtYPathList(floor(iteration)))
set iteration to (length > 0) ? dt*Speed/length : 0


Well, as there was still some mistake in my capx, I updated it with these new formula and some comments.
And I added a debug text you can set to visible to see how some of the values evolve.

kyat-PF.capx
Last edited by Yann on Sun Sep 14, 2014 8:30 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon May 21, 2012 4:27 am

It'd be a good idea to figure out the equation for having the sprite follow a already moving object. I'm trying to make a pac-man like game to sort of play around with this, and I'm beginning to wonder how I can get the sprite to follow the player. IS there a post I missed that has the equation for it?
B
14
S
4
G
5
Posts: 21
Reputation: 3,964

Post » Mon May 21, 2012 11:23 am

@TheOMP: there is an element listed in the how do I FAQ : Compagnon that follows the player - LINK

Maybe that helps ?
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Fri May 25, 2012 4:44 am

Not exactly what I was looking for but it might help regardless. I'm was thinking more of generating a path that leads to the player's last position and making the enemy follow that path.TheOMP2012-05-25 04:47:52
B
14
S
4
G
5
Posts: 21
Reputation: 3,964

Post » Tue Jul 17, 2012 4:43 am

It's possible to use it with moveto behavior? tried but got error
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Jul 17, 2012 11:21 pm

@Guif0DA: [QUOTE=TL22] You probably want something more like A* and pathfinding. 00Rez came up with a really sweet couple of plugins that can work in conjunction with one another to do what you're hoping. You can find them here in the Rez Repo topic. You can even find an example of using Rex's moveto in conjunction with the pathfinding behavior and A* plugin. Pretty cool stuff.[/QUOTE]
Quoted from the moveto behavior's topic.

I haven't tried it myself, but if there's already a provided example, it sounds like 00Rez's solution might be more suited to your needs.

I guess with my plugin, the iteration solution stands, iterating through the path's array, sending the next step's coordinates to the moveto behavior, and rely on a "on destination" trigger to iterate the next step.Kyatric2012-07-17 23:22:01
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 5 guests