Where Should I Share Reusable Pathfinder Code?
Posted: Mon Jan 28, 2013 1:16 am
As the current version of GE seems to lack even basic pathfinder code, I have created my own custom code that can be used as a pathfinder function. It's not meant for complex path finding or working through multiple directional choices in a road. It's intended to be used to walk around irregular structures without using the "Avoid" parameter (as that often results in the actor pointing in the wrong direction while walking, slowing his speed and walking around the invisible rectangle enclosing the object in case the object is irregular in shape).
I'd be happy to share this code with the community and provide a brief explanation on how it can be customized for your game. The code does the following:
1) Calculates the shortest path around an irregular object, taking into account the indents in the object (and not the rectangular periphery limits used by GE)
2) Moves the object to the destination (which is designated by clicking on the destination location with the mouse) along the above shortest path
3) Animates the object so that it always faces the direction in which it is currently travelling (and not just the final destination as GE does)
For point 3 above, I have created a function to make my actor play a different animation based on the direction in which it is moving. This function is called from within the pathfinder function. You can use your own function in its place - no parameters need to be passed or returned. I can provide my directional code as well and you can replace my actor and animation names with your own if you feel like getting into it.
I just want to clarify that this is not a pre-configured function that can simply be called by passing parameters to it (although once this is set up for your game, you can call it using a single function only). It's definitely possible to make it that easy (and I'd be glad if this could be incorporated into Game Editor), but for now, I've taken the easy way out by leaving it game-specific. Therefore, there will still be some basic but minimal code changes required (such as the number of points along the path, regions where the pathfinder is not required as there are no obstacles, etc.) to initially set this up for a specific game or a level in the game.
I'm not sure whether there is a specific section for this sort of thing. Please let me know if there is and I'll put up the code and a brief explanation on what needs to be customized for a game and which function needs to be called for this to work.
I'd be happy to share this code with the community and provide a brief explanation on how it can be customized for your game. The code does the following:
1) Calculates the shortest path around an irregular object, taking into account the indents in the object (and not the rectangular periphery limits used by GE)
2) Moves the object to the destination (which is designated by clicking on the destination location with the mouse) along the above shortest path
3) Animates the object so that it always faces the direction in which it is currently travelling (and not just the final destination as GE does)
For point 3 above, I have created a function to make my actor play a different animation based on the direction in which it is moving. This function is called from within the pathfinder function. You can use your own function in its place - no parameters need to be passed or returned. I can provide my directional code as well and you can replace my actor and animation names with your own if you feel like getting into it.
I just want to clarify that this is not a pre-configured function that can simply be called by passing parameters to it (although once this is set up for your game, you can call it using a single function only). It's definitely possible to make it that easy (and I'd be glad if this could be incorporated into Game Editor), but for now, I've taken the easy way out by leaving it game-specific. Therefore, there will still be some basic but minimal code changes required (such as the number of points along the path, regions where the pathfinder is not required as there are no obstacles, etc.) to initially set this up for a specific game or a level in the game.
I'm not sure whether there is a specific section for this sort of thing. Please let me know if there is and I'll put up the code and a brief explanation on what needs to be customized for a game and which function needs to be called for this to work.