Texture Movement Penalty Example?

HomeForumsA* Pathfinding ProjectSupportTexture Movement Penalty Example?

This topic has 2 voices, contains 23 replies, and was last updated by  Aron Granberg 117 days ago.

Viewing 15 posts - 1 through 15 (of 24 total)
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.


GraphUpdateObject guo = new GraphUpdateObject (someObject.collider.bounds);
guo.addPenalty = 1000; //Or some other large value, try with greater values if this doesn't affect anything
guo.updatePhysics = false; //Disable as there is no need for this
AstarPath.active.UpdateGraphs (guo);

(note: code typed directly in post, not checked)
This will add a penalty of 1000 to an area, you can reset it with the same code but -1000 as penalty when the object is destroyed.
Try this code out and view the effect by changing the debug mode (A* Inspector–>Settings) to Penalty and adjust the Roof value.

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,
Aron Granberg

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,
Bob

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.


using UnityEngine;
using System.Collections;
using Pathfinding;

public class TestObstacle : MonoBehaviour {

public GameObject delivery;
public Vector3 location;

// Use this for initialization

void Start () {
location.x = -0.9982949f;
location.y = 0.48f;
location.z = 1.487237f;

//instantiate
GameObject clone = new GameObject();
clone = Instantiate(delivery, location, Quaternion.identity) as GameObject;

//From Aron
GraphUpdateObject guo = new GraphUpdateObject(clone.collider.bounds);
guo.addPenalty = 10000000; //Or some other large value, try with greater values if this doesn't affect anything
guo.updatePhysics = false; //Disable as there is no need for this
AstarPath.active.UpdateGraphs (guo);
}

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:
GraphUpdateObject guo = new GraphUpdateObject (collider.bounds);
guo.updatePhysics = false;
guo.addPenalty = 10000;
AstarPath.active.UpdateGraphs (guo);

If I turn on Penalty as debug mode I see red areas where I have updated the grid.
Make sure your bounds objects totally cover at least one node.

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:

http://img7.imageshack.us/img7/9872/astarhelp0001.jpg

December 31, 2011 at 00:50 #1207

Bob

And here is a second photo that shows my debug options:

http://img851.imageshack.us/img851/4318/astarhelp0002.jpg

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:
http://www.mediafire.com/?545qbu75m2mbgwp

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.
Please download the latest (3.0.8.1) version of the system, and it will work fine, though if you are using windows you might want to wait an hour or two until I have uploaded 3.0.8.2 which fixes a critical windows related bug which could cause an error so you could not use the A* inspector.

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?

Viewing 15 posts - 1 through 15 (of 24 total)
Reply To: Texture Movement Penalty Example?
Your information:






<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>