Home › Forums › A* Pathfinding Project › Support › Texture Movement Penalty Example?
This topic has 2 voices, contains 23 replies, and was last updated by Aron Granberg 117 days ago.
| Author | Posts |
|---|---|
| Author | Posts |
| December 20, 2011 at 19:37 #1113 | |
|
Bob |
Hello, My AI will be interacting with (ahem…destroying) obstacles along their paths when necessary, and this will take time for them to accomplish. I want them to be able to account for this time when choosing the shortest path, and I was hoping that the texture movement penalty feature would be able to help them accomplish this. I wasn’t able to find any examples dealing with the texture feature, and I’ve found very little in the documentation about how it works. I know this is a pro version feature only, but this is a make or break feature for me, and I am hesitant to upgrade if this won’t actually solve my problem. Would you be able to provide a short example of how textures can be used to apply penalties to a path? Thank you very much, Bob |
| December 20, 2011 at 22:08 #1116 | |
|
Aron Granberg |
Hi Bob Texture penalties work simply by taking a channel value (R,G or B), multiplying it with some constant (which you set in the editor) and then apply that to the nodes in a grid graph. Units will try to avoid areas with high penalties. This won’t however update automatically when you update the texture, so I think the better option would be to use GraphUpdateObjects which can set the penalty of an area.
You are right in that I should add more documentation about it… but there is so much I need to add documentation about, so I can’t really keep up with it. I will see how it goes. Cheers,
|
| December 21, 2011 at 07:49 #1119 | |
|
Bob |
Hi Aron, Thanks for the thoughtful and detailed reply. I didn’t realize that GraphUpdateObject was an option I could pursue. I’ll look into using it, and report back with my successes/failures. Thanks, |
| December 27, 2011 at 02:03 #1146 | |
|
Bob |
Hi Aron, Unfortunately, I wasn’t able to get this feature to work at all. It could be because I still don’t know what I am doing, but I actually do think that I’m on the right track here. Here is the code i used to instantiate an object in the middle of my path. My seeker didn’t attempt to move around it and just got stuck. I didn’t see anything happen when I changed the debug mode to look at Penalty. Changing the roof value and my value for addPenalty had no effect with multiple tries. I attached this code to an empty game object, and passed the script a prefab (using the inspector) which is essentially a Cube with a box collider.
public class TestObstacle : MonoBehaviour { public GameObject delivery; // Use this for initialization void Start () { //instantiate //From Aron Interestingly enough, if I changed the layer of the prefab I passed in to this script in the inspector to “Obstacles”, it was seen as an obstacle, and the seeker moved around it correctly. I just couldn’t apply the penalty and have the seeker do the same. Any ideas? Thanks, Bob |
| December 28, 2011 at 17:10 #1157 | |
|
Bob |
I didn’t mention it, but this is using grids. Does anyone else use the Penalty feature successfully? Any help would be appreciated. Bob |
| December 28, 2011 at 17:35 #1158 | |
|
Aron Granberg |
I checked if penalties were broken, but they seem to work fine: |
| December 31, 2011 at 00:44 #1204 | |
|
Bob |
I’m very confused. It doesn’t matter if I make a object in my Hierarchy, or if I instantiate – it still doesn’t work. I am using the code from the “Getting Started” page (http://www.arongranberg.com/astar/docs/getstarted.php). I modified the Width (40), Depth (40), and node size (0.25). The rest is pretty much the same. I’ve taken your code and put it into a game object (just basic cubes with a collider), but the penalty just doesn’t seem to do anything. I’ve uploaded a screenshot of what I am seeing with the debug options you specified): I know it is a lot to ask, but if you don’t see what I am doing wrong from the photo, can I send you an example project to show you the problems I am having? Thanks, Bob |
| December 31, 2011 at 00:46 #1205 | |
|
Bob |
Oops, I forgot to close the tag in my post. The image is: |
| December 31, 2011 at 00:50 #1207 | |
|
Bob |
And here is a second photo that shows my debug options: |
| December 31, 2011 at 00:51 #1208 | |
|
Aron Granberg |
Yes, please send me a project so I can take a look at it. |
| December 31, 2011 at 00:52 #1209 | |
|
Bob |
And if it wasn’t clear from the photos, the “cubes” shown have had the penalties applied to them in code. The walls are in the obstacle layer. |
| December 31, 2011 at 01:33 #1210 | |
|
Bob |
Thanks! I’ve uploaded the unity project here: |
| December 31, 2011 at 12:00 #1212 | |
|
Aron Granberg |
Ah, found the problem, you are using version 3.0.6 of the system, a version which had the unfortunate bug that penalties using Graph Update Object on grid graphs were broken. They would get set, however they would get reset ten lines of code after they had been set. |
| January 5, 2012 at 05:28 #1233 | |
|
Bob |
That is music to my ears. I\’m glad I\’m not going crazy. It works great now that I\’ve upgraded. Thank you so much for your help. Bob |
| January 19, 2012 at 06:59 #1322 | |
|
msleeper |
I’m having an issue of my own with GraphUpdateObject’s and causing lag spikes, I suspect I’m simply Doing It Wrong but I’m not sure the solution. I have a handful of objects that move around with references to their gameobject’s saved in an array, and when they start their pathfinding, I need them to rebuild the penalties so that they will avoid each other. I’m doing this when they start moving so that if they are all stopped in a bunch, they won’t get into a big traffic jam when they start their initial pathfinding. However, there is a big lag spike when I tell all of them to move when they recalculate the penalties. Is that a really expensive operation, or should I not be updating the graph with penalties that frequently? |