Jump to content


Photo

Motion Planning Action Library


  • Please log in to reply
14 replies to this topic

#1 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 04 May 2011 - 04:08 AM

Hello! I have made an action library that is designed for beginners to use motion planning within their levels. I originally made this for a friend, but decided to share it with the community!

The actions for this lib include:
  • Create MP Grid
  • Destroy MP Grid
  • Add Cell
  • Add Rectangle
  • Add Instance
  • Add All Instances
  • Clear Cell
  • Clear Rectangle
  • Clear All Cells
  • Initialize Path
  • Calculate MP Path
  • Start MP Path
  • Draw MP Grid
  • Draw MP Path
  • Test MP Path

The zip file includes the action library (.lib), Extension (.gex), and a help file on how to use the action library, and installation directions. Make sure to read the Help file before asking any questions :)

This is my first lib, and I hope you enjoy it!

Compatibility: Version 8.0 + 8.1
Files included: .gex, .lib, .chm

Download v1.2
Download 2 (Box.net)

Screenshot :)
Posted Image

Edited by Kojak, 21 May 2011 - 03:55 AM.

  • 0

#2 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 05 May 2011 - 10:41 PM

Updated to Version 1.1.

Added New Function - Test MP Grid: Checks to see if the path is possible.
  • 0

#3 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 10 May 2011 - 08:01 PM

hey this is cool but for the game im working on at the moment i need an action which returns the x and y coordinate of the next destination point on the path and also one for the point after the next point... hopefully that wouldnt be too hard to add :) i need it to make this work with my collision codes. maybe include a drop down option that says next or after next. and also make it so you can type in the variable name you would like to give to the returned x or y value.. thanx in advance.
oh and also this may just be because im bad at using this but i cant find a way to make multiple characters track your mouse while avoiding eachother, i tried adding each character to the grid but then the path wouldnt calculate.

Edited by papermaul, 10 May 2011 - 08:41 PM.

  • 0

#4 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 12 May 2011 - 03:13 AM

hey this is cool but for the game im working on at the moment i need an action which returns the x and y coordinate of the next destination point on the path and also one for the point after the next point... hopefully that wouldnt be too hard to add :) i need it to make this work with my collision codes. maybe include a drop down option that says next or after next. and also make it so you can type in the variable name you would like to give to the returned x or y value.. thanx in advance.


I really don't understand what you are talking about lol
Are you talking about when the object your are moving makes a turn?
Please clarify ;)

oh and also this may just be because im bad at using this but i cant find a way to make multiple characters track your mouse while avoiding eachother, i tried adding each character to the grid but then the path wouldnt calculate.


You are unable to accomplish this with just the actions provided in this library. The reasoning behind that is how the grid-based approach works. Since you can't attach a cell to a moving object, you must set an alternative way to compute the path when near another enemy I am trying to use this in coordination with mp_potential_path, but for some reason the game keeps freezing after a few seconds of it working. Once I find a solution to this, then I would be sure to add this as a function.
  • 0

#5 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 12 May 2011 - 04:41 AM

I really don't understand what you are talking about lol
Are you talking about when the object your are moving makes a turn?
Please clarify ;)

what i mean is... well the paths are made of waypoints or nodes or whatever they are called. i just need a function which returns the coordinates of the next waypoint(or node or whatever).. because that would allow me to bypass the whole multiple object pathfinding problem by just putting in a smooth collision engine. the engine i have currently doesnt work with speed but with the next waypoint's (or node's or whatever)coordinates it would. obviously it would not be as good as if you found a way to make objects pathfind in groups but it is the next best thing.

hopefully this clarifies... im not good at explaining things :P

You are unable to accomplish this with just the actions provided in this library. The reasoning behind that is how the grid-based approach works. Since you can't attach a cell to a moving object, you must set an alternative way to compute the path when near another enemy I am trying to use this in coordination with mp_potential_path, but for some reason the game keeps freezing after a few seconds of it working. Once I find a solution to this, then I would be sure to add this as a function.


i have been playing around with this as well using your engine and i came up with something that might (or might not) be useful to you because it kind of works... i have a control object which checks every square's distance from the target and then numbers it. the objects move towards the target but when the target is blocked they automatically target the next lowest number available until that too is blocked. it works well but unfortunately does not stop objects walking through eachother among other problems such as if the target is in a horse-shoe shaped wall then the objects will find positions around the outside of the wall which i do not want :/
  • 0

#6 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 13 May 2011 - 01:24 AM

what i mean is... well the paths are made of waypoints or nodes or whatever they are called. i just need a function which returns the coordinates of the next waypoint(or node or whatever).. because that would allow me to bypass the whole multiple object pathfinding problem by just putting in a smooth collision engine. the engine i have currently doesnt work with speed but with the next waypoint's (or node's or whatever)coordinates it would. obviously it would not be as good as if you found a way to make objects pathfind in groups but it is the next best thing.

hopefully this clarifies... im not good at explaining things :P


Actually, the path is set as a new created path resource using the function path_add and setting it to the variable mppath. The path made in this engine is not actually composed of nodes but as a path resource. This is the reason that the initialization function is needed for each object moving on the grid. The GML equivalent for the initialization function is:

mppath = path_add();

The function to calculate the path stores the calculated path into the resource mppath. It doesn't really create 'nodes' but rather a path resource. Therefore, you can start this path with a simple path_start function. If you know how to manipulate paths, then you would be able to achieve what you want.
I'm a noob, so I wouldn't know how to do what you want to accomplish :P

i have been playing around with this as well using your engine and i came up with something that might (or might not) be useful to you because it kind of works... i have a control object which checks every square's distance from the target and then numbers it. the objects move towards the target but when the target is blocked they automatically target the next lowest number available until that too is blocked. it works well but unfortunately does not stop objects walking through eachother among other problems such as if the target is in a horse-shoe shaped wall then the objects will find positions around the outside of the wall which i do not want :/


Maybe if you keep working with your solution, it just might be useful ;)
The thing is that my way of doing it works really well, but it just...freezes after a few seconds :(

Also, don't refer to this as my 'engine'. The actions in this library are just equivalents to GML pathfinding functions. I just made this to make it easier for some people who prefer D&D. Of course, GML would be better ;)
As a matter of fact, for the next update of this lib, I would add the actions and their GML equivalents in the Help file to help beginners take a step up towards GML.
If you go to the Game Maker Help file, in The Game Maker Language (GML) > Game Play > Motion Planning, you would find the functions used for this library in the bottom of that page.
  • 0

#7 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 13 May 2011 - 04:48 AM

Actually, the path is set as a new created path resource using the function path_add and setting it to the variable mppath. The path made in this engine is not actually composed of nodes but as a path resource. This is the reason that the initialization function is needed for each object moving on the grid. The GML equivalent for the initialization function is:

mppath = path_add();

The function to calculate the path stores the calculated path into the resource mppath. It doesn't really create 'nodes' but rather a path resource. Therefore, you can start this path with a simple path_start function. If you know how to manipulate paths, then you would be able to achieve what you want.
I'm a noob, so I wouldn't know how to do what you want to accomplish :P


rite im very much a noob with pathfinding so when you initiate the path with your lib how can you retrieve the path's ID or index or whatever so i can do stuff with it in code? maybe i can find a way to still use it with what im trying to do...

Maybe if you keep working with your solution, it just might be useful ;)
The thing is that my way of doing it works really well, but it just...freezes after a few seconds :(


maybe if you could explain ur method i could help? so what i have is kind of working right now. what im doing is in the step event before the path is added for the object that is pathfinding the object in question will add all the instances of its object type to the grid and then remove the square it is on. this is because the objects tend to move through eachother and such while pathfinding. next it checks whether the targetted cell is already targetted or blocked by another instance of the same object type and if this is false it will target that cell and set the cells targetted variable in an array to true so that the next object will not be able to target the same cell... then if the cell is targetted it will use what i explained earlier (the distance each cell is from the target) to see what the next best option is and target that cell and then set that cell's targetted value to true so this would work for any number of objects. hopefully that stuff makes sense. anyways this works fine but the problem is if the target is in a horse-shoe shaped wall-thing then the next best option where distance is concerned might be a cell that is outside the horseshoe which i obviously do not want since im making an rts engine. because of this if there was any way at all for you to add to your library ,or maybe if there was a way to code it in gml (i prefer coding),a function which returns the length of a path then what i would do is change the prioritizing of cells from the distance to the target to the distance the target would have to move to reach that cell... and if i had this it would work perfectly.

Also, don't refer to this as my 'engine'. The actions in this library are just equivalents to GML pathfinding functions. I just made this to make it easier for some people who prefer D&D. Of course, GML would be better ;)
As a matter of fact, for the next update of this lib, I would add the actions and their GML equivalents in the Help file to help beginners take a step up towards GML.


that would be helpful! im not exactly a beginner but where path finding is concerned i am.

If you go to the Game Maker Help file, in The Game Maker Language (GML) > Game Play > Motion Planning, you would find the functions used for this library in the bottom of that page.


ill do that :)
but still to sum up it would be nice if for the next version you could add either my previous request for node coordinates or a thing to measure the total length of the path.

oh yeah here is what i have so far if you want to have a look. theres a bug which causes the blue guys to vibrate between two possible targets tho... i dont know why...
http://www.megaupload.com/?d=N51HYMSX

Edited by papermaul, 13 May 2011 - 11:33 AM.

  • 0

#8 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 14 May 2011 - 09:08 PM

anything going on here? :P
  • 0

#9 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 16 May 2011 - 02:11 AM

The id of the path is mppath I believe, and the index can be retrieved from the object moving along the path, for example, enemy.path_index.

The local variable path_position can be used to find the position you are on within the path. This can be a problem though if the path is calculated each step, as the variable would stay extremely low until the path is finished.

Here is a basic explanation of how my attempted method works:
Whenever the enemy is close to each other, the function mp_potential_path would execute. If they aren't close together, then mp_grid_path is used.

It works for a bit, then my game freezes. I have no idea how to fix it either :(


I'm sorry that I really can't help you, since I myself don't know how to retrieve the node coordinates. :(

These functions might help though:

path_exists(ind) Returns whether a path with the given index exists.
path_get_name(ind) Returns the name of the path with the given index.
path_get_length(ind) Returns the length of the path with the given index.
path_get_kind(ind) Returns the kind of connections of the path with the given index (0=straight, 1=smooth).
path_get_closed(ind) Returns whether the path is closed or not.
path_get_precision(ind) Returns the precision used for creating smoothed paths.
path_get_number(ind) Returns the number of defining points for the path.
path_get_point_x(ind,n) Returns the x-coordinate of the n'th defining point for the path. 0 is the first point.
path_get_point_y(ind,n) Returns the y-coordinate of the n'th defining point for the path. 0 is the first point.
path_get_point_speed(ind,n) Returns the speed factor at the n'th defining point for the path. 0 is the first point.
path_get_x(ind,pos) Returns the x-coordinate at position pos for the path. pos must lie between 0 and 1.
path_get_y(ind,pos) Returns the y-coordinate at position pos for the path. pos must lie between 0 and 1.
path_get_speed(ind,pos) Returns the speed factor at position pos for the path. pos must lie between 0 and 1.

To get the name of a path the enemy is on, you can use path_get_name(enemy.path_index).

And to solve the length issue, you can use path_get_length.

I hope that helped :)
  • 0

#10 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 16 May 2011 - 07:23 AM

wow that actually does help a LOT! thanx so much :P but hey when i finished group motion planning ill give it to u so u can add some functions to the library. my script will work perfectly with the functions you just listed :P i think im just a total noob with pathfinding. it might take me a few days to finish tho, im busy a lot with schoolwork and other stuff. ill get back to you when its done.
  • 0

#11 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 16 May 2011 - 08:06 AM

oh yeah what is the code equivalent to the calculate path library function?
  • 0

#12 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 16 May 2011 - 09:26 PM

I'll post code equivalents when I have time, and add them to this post, and the help file in the next update. :)
  • 0

#13 papermaul

papermaul

    GMC Member

  • New Member
  • 52 posts

Posted 17 May 2011 - 04:24 AM

ok cool but if i had the calculate path one then i can finish my group motion planning... it works perfectly right now i just need to put calculate path inside a loop to make sure that objects move towards the correct position
  • 0

#14 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 20 May 2011 - 04:50 PM

ok cool but if i had the calculate path one then i can finish my group motion planning... it works perfectly right now i just need to put calculate path inside a loop to make sure that objects move towards the correct position


mp_grid_path(global.mpgrid,mppath,xstart,ystart,xgoal,ygoal,allowdiag)

  • 0

#15 Kojak

Kojak

    GMC Member

  • New Member
  • 78 posts

Posted 20 May 2011 - 09:09 PM

New Version v1.2

Changes:
Added GML code equivalents page. :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users