[Behavior]PathFinder

Forum Home Forum Home > Construct 2 Development > Plugins for Construct 2
 Post Reply Post Reply Page  <1 7891011 13>
Author
453 Rep
Post Options Post Options   Quote yumarod3 Quote  Post ReplyReply Direct Link To This Post Posted: 28 Mar 2012 at 12:44am
I updated the link into Dropbox :)
Back to Top

Moderator
29,727 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 28 Mar 2012 at 2:04am
@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.

Edited by Kyatric - 28 Mar 2012 at 2:06am
Back to Top
4,931 Rep
Post Options Post Options   Quote EyeHawk Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2012 at 10:56pm
@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 :)
Back to Top
11,750 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2012 at 2:40pm
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
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.

http://dl.dropbox.com/u/23551572/C2/kyat-PF.capx

Edited by Yann - 20 May 2012 at 2:44pm
Back to Top
2,092 Rep
Post Options Post Options   Quote TheOMP Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2012 at 4:27am
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?
Back to Top

Moderator
29,727 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2012 at 11:23am
@TheOMP: there is an element listed in the how do I FAQ : Compagnon that follows the player - LINK

Maybe that helps ?
Back to Top
2,092 Rep
Post Options Post Options   Quote TheOMP Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2012 at 4:44am
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.

Edited by TheOMP - 25 May 2012 at 4:47am
Back to Top
2,775 Rep
Post Options Post Options   Quote Guif0DA Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jul 2012 at 4:43am
It's possible to use it with moveto behavior? tried but got error
Back to Top

Moderator
29,727 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jul 2012 at 11:21pm
@Guif0DA:
Originally posted by TL22 TL22 wrote:

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.

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.

Edited by Kyatric - 17 Jul 2012 at 11:22pm
Back to Top
2,775 Rep
Post Options Post Options   Quote Guif0DA Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jul 2012 at 12:56am
Originally posted by Kyatric Kyatric wrote:

@Guif0DA:
Originally posted by TL22 TL22 wrote:

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.

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.

Thanks for reply!
I would like to use your pathfinding than the one from REZ, your seems more complex, with more actions and expressions.
The example that uses moveto uses the pathfinding from REZ..
But I will try again to make it work and see if this time the game doesn't crash.
Back to Top
 Post Reply Post Reply Page  <1 7891011 13>

Forum Jump Forum Permissions View Drop Down