Search Unity

A* Pathfinding Project 3.0 is Released!

Discussion in 'Assets and Asset Store' started by half_voxel, Aug 10, 2011.

  1. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @GamesFoundry
    10 points to you! You've found a bug!
    The value was not even serialized (doh) but I added it now, so it will be fixed in the next version.

    @FutureRobot
    Try Tools > Preferences > Unity > Debugger and turn off "Build project in MonoDevelop". MonoDevelop doesn't like default parameter values even though C# supports them.

    I'm not sure about intellisense though, in all my projects where I use monodevelop it works sometimes, but not always. I have really no idea what's causing it (if someone else knows anything, please fill in).
     
  2. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    Yeah, intellisense in monodevelop seems to drop out sometimes, a restart usually fixes it. Not much help I can be there.

    It appears to be the error that blocks me from autocompleting functions in the seeker and Astarpath classes. The normal monobehaviour stuff autocompletes as normal. When I removed the =null from the seeker and saved, I could access it as normal. (Put them right back though, was just testing :))

    I'll try turning off the build and see if it helps, thanks!

    What actually lead me to this issue was trying to make some simple avoidance between my seekers by updating the graph around each agent reserving his current node. Thought I'd ask if you have any suggestions regarding the best way to implement some simple "path-around-each-other" behaviour.

    I'm developing for mobile so the agents have no collision checks between each other in order to avoid the performance drop mass collisions create. And by "mass collisions" I mean just 6-7 can cause the fps to drop below 30 on an iphone 4. Your pathfinder runs smoothly though, and it would be great if I can use it to keep the characters from piling up on each other.
     
    Last edited: Sep 1, 2011
  3. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    I added a debug line, confirming that multithreading was disabled in the duplicate astarpath. Trying your suggestion, it now shows useMultithreading == true, and I can see various thread related debug info which I couldn't before. However, it is no longer able to generate paths...

    Code (csharp):
    1.  
    2. CharacterBase:OnPathComplete(Path) (at Assets\Resources\Scripts\Characters\CharacterBase.cs:477)
    3. Seeker:OnPathComplete(Path, Boolean, Boolean) (at Assets\AstarPathfindingProject\Core\Seeker.cs:183)
    4. Seeker:OnPathComplete(Path) (at Assets\AstarPathfindingProject\Core\Seeker.cs:158)
    5. Pathfinding.Path:ReturnPath() (at Assets\AstarPathfindingProject\Pathfinders\Path.cs:603)
    6. AstarPath:StartPath(Path) (at Assets\AstarPathfindingProject\Core\AstarPath.cs:1125)
    7. Seeker:StartPath(Path, OnPathDelegate) (at Assets\AstarPathfindingProject\Core\Seeker.cs:309)
    8. Seeker:StartPath(Vector3, Vector3, OnPathDelegate) (at Assets\AstarPathfindingProject\Core\Seeker.cs:266)
    9.  
     
  4. netics

    netics

    Joined:
    Aug 23, 2011
    Posts:
    102
    Feature Request?

    How about checking Line of Sight area when using grid graph.

    It will be helpful for visualizing fog of war in rts game, or LoS in top-view shooter.
     
  5. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Ah, I had forgot about that. To avoid errors after destroying an AatarPath component, I set a flag to disable any future path calculations on that component.
    Well, I think you will have to wait til the next update, I will try to get it released today.
     
  6. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    Silly question...in the example scene, the "player" follows the cursor everywhere it moves. How can I change this so that it only follows the cursor on double click?
     
  7. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    Turning off Build Projects in Monodevelop didn't help.

    Downloaded and set unity to use the latest monodevelop Beta and default parameters work fine there, allowing me to autocomplete both seeker. and AstarPath.

    I'm not completely sure what problems I might run into with not using the custom unity monodevelop though...
     
  8. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Yey! You are right using MonoDevelop beta works! So it means that it's only a matter of time before autocomplete is fixed!

    @Chasiubao
    You will have to modify the TargetMover.cs script, to instead of updating the target position every frame, do it on double-click.
     
  9. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    3.0.5 is now released!

    Changelog - 3.0.5
    • List Graphs now support UpdateGraphs. This means that they for example can be used with the DynamicObstacle script.
    • List Graphs can now gather nodes based on GameObject tags instead of all nodes as childs of a specific GameObject.
    • List Graphs can now search recursively for childs to the 'root' GameObject instead of just searching through the top-level children.
    • Added custom area colors which can be edited in the inspector (A* inspector --> Settings --> Color Settings --> Custom Area Colors)
    • Fixed a NullReference bug which could ocurr when loading a Unity Reference with the AstarSerializer.
    • Fixed some bugs with the FleePath and RandomPath which could cause the StartEndModifier to assign the wrong endpoint to the path.
    • Documentation is now more clear on what is A* Pathfinding Project Pro only features.
    • Pathfinding.NNConstraint now has a variable to constrain which graphs to search (A* Pro only).
      This is also available for Pathfinding.GraphUpdateObject which now have a field for an NNConstraint where it can constrain which graphs to update.
    • StartPath calls on the Seeker can now take a parameter specifying which graphs to search for close nodes on (A* Pro only)
    • Added the delegate AstarPath.OnAwakeSettings which is called as the first thing in the Awake function, can be used to set up settings.
    • Pathfinding.UserConnection.doOverrideCost is now serialized correctly. This represents the toggle to the right of the "Cost" field when editing a link.
    • Fixed some bugs with the RecastGraph when spans were partially out-of-bounds, this could generate seemingly random holes in the mesh

    The free version can be downloaded again from the download page. Those of who have bought the Pro version can download it again from the link you got in the purchase confirmation email.
     
  10. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Is multithreading enabled on the free version now or is it an error on the comparison page?
     
  11. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @niosop
    No, that was an error on the comparison page. I have no idea of how it got there, I'm sure I checked everything was correct the last time I updated it...
     
  12. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    100*100*100 is massive :) looking super forwards to it- thanks sturestone
     
  13. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Excellent, just picked up a Pro license off your site. I was considering waiting to see how well Unity's implementation works in 3.5, but I'm sure it won't be as full featured and they definitely won't be as quick to respond to bugs and feature requests as you are.
     
  14. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Thanks for getting out the new release quickly.

    Might you consider setting the default for show unwalkable nodes to be false - after several crashes I remembered your advice and got it working again. Not sure if you have a note in your documentation already (or on the order confirmation email), but it appears necessary to extract the unity package from the zip file before installing it otherwise Unity throws up an error.

    New problem: when I enable multithreading using OnAwakeSettings, I get the following error. I got the same error in 3.0.4 but was holding off for 3.0.5 to see if it would be resolved:

    Code (csharp):
    1.  
    2. UnityEngine.Object:FindObjectsOfType(Type)
    3. UnityEngine.Object:FindObjectOfType(Type) (at C:\BuildAgent\work\842f9557127e852\Runtime\ExportGenerated\Editor\UnityEngineObject.cs:90)
    4. AstarPath:get_active() (at Assets\AstarPathfindingProject\Core\AstarPath.cs:261)
    5. Pathfinding.Path:Prepare() (at Assets\AstarPathfindingProject\Pathfinders\Path.cs:189)
    6. AstarPath:CalculatePathsThreaded() (at Assets\AstarPathfindingProject\Core\AstarPath.cs:1418)
    7.  
    At run-time I can confirm that my original terrain has had the AstarPath component removed, and that a well configured duplicate AstarPath exists on my terrain duplicate. So there should be a single instance of AstarPath with a single grid graph.

    Here's my code:

    Code (csharp):
    1.  
    2. AstarPath.OnAwakeSettings += ApplySettings;
    3. AstarPath astarPath = newTerrain.AddComponent<AstarPath>();
    4. AstarSerializer3_04 serializer = new AstarSerializer3_04(astarPath);
    5. astarPath.astarData.data = terrainByteData;
    6. astarPath.astarData.DeserializeGraphs(serializer);
    7. astarPath.Scan();
    8.  
    Code (csharp):
    1.  
    2. public void ApplySettings()
    3. {
    4.     AstarPath.OnAwakeSettings -= ApplySettings;
    5.     AstarPath.active.useMultithreading = true;
    6.     AstarPath.active.showNavGraphs = false;
    7.     AstarPath.active.showGraphs = false;
    8.     AstarPath.active.showUnwalkableNodes = false;
    9. }
    10.  
    If I implement the OnDestroy and Awake functions as per your previous posts, I don't get an error, but no seekers are able to generate valid paths, leaving my characters frozen.

    On a separate issue, I've defined a series of zero-cost links for my preferred highways (blue), which my characters are currently ignoring (see screenshot). How do I boost the importance of these highways so that characters are more likely to follow them? I tried setting node penalty to 5, but I think it's being overwritten.

    $Capture.JPG
     
    Last edited: Sep 3, 2011
  15. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    @sturestone

    I tried modifying TargetMover.cs, but I can't seem to get it to work. In fact, even when I comment out all the code in the Update() function of TargetMover.cs expecting my player to not move at all, it's still moving to wherever I move my cursor. The closest that I've gotten this to semi-work is in AIFollow.cs, where I added something like this:

    Code (csharp):
    1.  
    2.     public void OnGUI () {
    3.         Event e = Event.current;
    4.         if (e.isMouse  e.type == EventType.MouseDown  e.clickCount == 2)
    5.         { // Double click event
    6.             move = true;       
    7.         }      
    8.     }
    9.  
    10.     public void Update () {
    11.              if (move == true) {
    12.                   //do everything else
    13.              }
    14.         }
    15.  
    16.  
    This will, of course, only stop the player from moving as soon as the game starts, but once the player starts moving and I move my cursor, the player to move to the new path. Any ideas?

    Thanks!
     
  16. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632

    Where are you setting move back to false?
     
  17. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    @gamesfoundry

    I haven't found a place where I can set move back to false that would make this work. I tried setting it to false right before the line ReachedEndOfPath (); in Update() function, but that doesn't seem to work either.
     
  18. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Gamesfoundry

    I couldn't replicate that exact error, but I got another error which I think was caused by the same thing.
    The problem was that when calling OnDestroy (), OnDrawGizmos is still being called, in OnDrawGizmos, it was constantly setting AstarPath.active = this; Which could cause active to become null in some cases. I have fixed it now with that OnDrawGizmos will only set active to this if active was null before which will prevent it from overwriting the value the newly created AstarPath object was setting.
    I will release an update shortly.

    @chasiubao
    This code will only update the position of the target when the user double-clicks:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TargetMover : MonoBehaviour {
    5.    
    6.     //Mask for the raycast
    7.     public LayerMask mask;
    8.    
    9.     public Transform target;
    10.    
    11.     Camera cam;
    12.    
    13.     public void Start () {
    14.         //Cache the Main Camera
    15.         cam = Camera.main;
    16.     }
    17.    
    18.     public void OnGUI () {
    19.        
    20.         if (cam != null  Event.current.type == EventType.MouseDown  Event.current.clickCount == 2) {
    21.             //Fire a ray through the scene at the mouse position and place the target where it hits
    22.             RaycastHit hit;
    23.             if (Physics.Raycast (cam.ScreenPointToRay (Input.mousePosition), out hit, Mathf.Infinity, mask)) {
    24.                 target.position = hit.point;
    25.             }
    26.         }
    27.     }
    28.    
    29.     // Update is called once per frame
    30.     /*void Update () {
    31.        
    32.         if (cam != null) {
    33.            
    34.            
    35.         }
    36.        
    37.     }*/
    38.    
    39. }
    If you want it to be stationary at start, set the target to the same position as the player as the initial position.
     
  19. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Regarding the "highways". It's probably because the search is not expanding enough to include them in the search, try to decrease the "Heuristic Scale" (settings --> Pathfinding --> Heuristic Scale), then the search will include more nodes.
     
  20. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Starting to get a C++ version of Recast available in Unity (editor only). Seems to work quite well, and the scan time is way lower than my C# version. Now I have Recast reading a .obj file and sending the output to Unity, I will soon add a way for Unity to send input to Recast which can built a navmesh from it.
     
  21. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    This might have been covered before but how is this usable with the Unity Pro Skin? Example image provided...
     

    Attached Files:

    Last edited: Sep 4, 2011
  22. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    If you're using the latest version, in one of the sections there's a Pro skin checkbox that changes the color scheme.
     
  23. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Ok, thanks, will have a hunt for it. Obviously there is no way to detect if the user is using the Pro Skin and do an auto switch. Bummer.
     
  24. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    I tried this but couldn't get anything working, even at 0.01 scale - it was obviously testing more nodes, as the search speeds were slower as you would expect. So I tried using a texture for penalties and walkability. Is there a documentation page on this? what is the orientation of the texture axis to world axis? I tried showing debug data for penalties but that didn't seem to do anything.

    I'm now using an optimized navmesh covering my entire map, but I'm getting really low FPS in the editor - even when I disable the AstarPath component. It's only when I delete the AstarPath from the terrain that FPS increases back to normal. It's like it's drawing the navmesh every frame even though nothing is appearing.

    Once I do get my project running, after loading the saved graph data from the HDD, everything freezes up. Looking at the log...

    Code (csharp):
    1.  
    2. Forced to discard nodes because of binary heap size limit, please consider increasing the size (5000 5000)
    3. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    4. UnityEngine.Debug:Log(Object)
    5. Pathfinding.BinaryHeap:Add(Node) (at Assets\AstarPathfindingProject\Core\astarclasses.cs:918)
    6. Pathfinding.Node:BaseUpdateAllG(BinaryHeap) (at Assets\AstarPathfindingProject\Core\astarclasses.cs:248)
    7.  
    The last two lines start repeating ad-infinitum. I'll boost my heap size to try and remove this.

    EDIT: no joy, Unity is freezing.
     
    Last edited: Sep 4, 2011
  25. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    @sturestone

    Thanks! I got my mouse clicks working now. I have another newbie question. In my scene, I have 2 floors connected by a staircase where the player can go up and down to. Am I suppose to render my grid graph twice, once on each floor? Or am I suppose to do just one? I tried both ways and neither was really working for me, though I'm pretty sure I'm doing something wrong.

    Many thanks!
     
  26. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Chasiubao
    Grid graphs are 2D, mostly because they then use much mess memory and they are faster.
    What you do for 2 floors is either make a navmesh in your favorite 3D modeling app (or buy the Pro version and tell it to automatically generate a navmesh for you), or make two grids connected by links which you create in the scene view.
    I would go for the navmesh approach as it is more stable, but it depends a lot on the game.

    As a side note: I've got Javascript support working!
    Unfortunately though, Javascript does not like the default parameters, so I have to fill in every one of them... I guess I have to create a few overloads for commonly used functions.

    I will also try to get a small dialog box working at first run asking about if the user want to use the Dark or Light skin as a lot of people seem to have trouble finding the setting (it's in Settings-->Editor-->Use Dark Skin btw).
     
  27. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hey! I think I have found a way to get info on if the user is using the Dark Skin or the Light Skin in Unity, it is stored in the .plist file which Unity uses, I had tried to use it before, but what I did wrong was that it was not a boolean, it was stored as an int which could be 0 or 1.
    I haven't got Pro to test it, but I will add it to the next version.
     
  28. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    I'll be happy to test it if you want to send me the changes.
     
  29. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Niosop

    Sent you a test version!
    Tell me how it works.
     
  30. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Gamesfoundry Yes, because it is expanding a lot more (at 0.01 it's like a Djikstra's search), you will need a larger heap size.
    I'm not sure why it doesn't follow your highways, I will run some tests myself.

    PS: Perhaps you will find this function useful : EditorUtility.CopySerialized
     
  31. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    @sturestone

    I purchased your Pro version and tried using it on the example scene by replacing the default grid graph with the recast graph. When I play the scene, the capsule seems to always just "dance" around the target but never reaches it, and it doesn't stop moving. I tried playing with the settings but nothing seems to fix it.

    Any ideas?

    $screenshot.jpg
     
  32. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    You'll want to modify the movement script to check the distance to target and stop seeking/moving when it's close enough. It has nothing to do with the pathfinding, that should be handled with your movement logic.
     
  33. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    Oh! I didn't change any of the other scripts thinking the setup in the example scene should work the same no matter what graph I use. By movement script, I think you're referring to AIFollow.cs. I'll give it a try! Thanks!
     
  34. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    I also notice that your mask includes Everything. If your target had some kind of mesh attached and you leave it at the default position, it will not be able to reach it because there is a hole in the navmesh right there.
     
  35. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    PS: Also check the Start End Modifier settings, both Start and End should be exact.
     
  36. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Hello, I'm having trouble getting the pathfinding to work on iPhone (iOS) - the pathfinding works fine in the editor and if I build it to the web, but not on the iPhone.

    From what I can tell, the Vector3 path array is not being filled with all of the paths OnPathComplete. On the iPhone, path.Length only ever returns 1 while in the editor all of the paths are added to the array.

    I'm using the free version 3.0.5 and Unity 3.4 Pro w/ iPhone basic. And I'm using a ListGraph for my grid.

    Here's a trimmed down version of my code so you can see how I'm collecting the paths:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Pathfinding;
    4.  
    5. public class Controls : MonoBehaviour {
    6.  
    7.     public Transform targetTransform;
    8.     public LayerMask mask; 
    9.     private bool interact = false;
    10.     private Touch touch;
    11.  
    12.     private Vector3[] path;
    13.     private Seeker seeker;
    14.  
    15.     void Start () {
    16.         seeker = GetComponent<Seeker>();
    17.     }
    18.    
    19.     void Update() {
    20.         // snip snip...touch code goes here
    21.         if (touch.phase == TouchPhase.Ended) {
    22.             if (Physics.Raycast (ray, out hit, Mathf.Infinity, mask)) {
    23.                 targetTransform.position = new Vector3(hit.point.x, hit.point.y, -.1f);
    24.                 RePath();
    25.             }
    26.         }
    27.     }
    28.    
    29.     void RePath() {
    30.         seeker.StartPath (transform.position,targetTransform.position, OnPathComplete);
    31.     }
    32.    
    33.     void OnPathComplete(Path p) {
    34.         path = p.vectorPath;
    35.         print(path.Length); // returns correct number in editor, returns only 1 on iPhone
    36.        
    37.         // move stuff goes here
    38.     }
    39.    
    40. }
     
  37. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hmm... And the log doesn't say anything else interesting? (turn on Heavy logging in A* Inspector --> Settings).
     
  38. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Hi, thanks for the fast reply. Here's the output from the Xcode debugger console with path log mode set to "heavy".

    While Deserializing:
    After touching the screen which should have sent my character moving to the touch point:
    For comparison, here's the debug output from unity when clicking close to the same destination point in the editor:
     
    Last edited: Sep 5, 2011
  39. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Any news on when the next build will be available?

    Modifiers - Click here for more info link is broken.
    How do I remove a modifier? - EDIT: ignore this, stupid question!
     
    Last edited: Sep 6, 2011
  40. chasiubao

    chasiubao

    Joined:
    Jun 1, 2011
    Posts:
    19
    @sturestone

    I'm out of ideas. No matter what settings I choose (Exact start/end points, Masking only my "ground" layer, adding a funnel modifier) I can't seem to get my player to stop orbiting the target at least 5 to 6 times before it will stop.

    Also, when I try to import your pro package into my Mac, I get weird errors like:

    Assets/AstarPathfindingProject/Generators/GridGenerator.cs line 43 - error CS0246: The type or namespace name "Color32" could not be found. ...

    Do you know how to fix these?

    Thanks!!
     
  41. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Chasiubao

    The webpage you linked to in the PM requires me to enter username and password.

    Ah, Color32 is new for Unity 3.4, I have added a #define for it so it should not throw errors in Unity 3.3 anymore, but you will have to upgrade to 3.4 if you want to use the Use Texture option.
    In the meantime, you can comment out the data variable, and everything inside the Initialize and Apply functions in the TextureData class (in the GridGenerator.cs script).

    @Gamesfoundry
    Thanks for the tip, it should have been .php not .html.
     
  42. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    @sturestone I'm still trying to get my pathfinding to work on the iPhone. A GridGraph WILL work properly on the iPhone, but a ListGraph will not. Any ideas why ListGraph's might be broken on iPhone? Is there any way to find out if all of the graph nodes are present in the device build?
     
  43. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Meanstreak... so a Grid Graph will work... I really hope not... but it might be the serialization of the "Root" object which is failing. Try to run the code:
    Code (csharp):
    1. Debug.Log ((AstarPath.active.astarData.graphs[0] as ListGraph).root != null ? "The root object exists" : "The root object does not exist");
    Some time after startup (in Start () for example).
    (wrote the code on the forum, I hope it compiles, there must be a ListGraph attached as the first graph).
     
  44. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    It's printing out "The root object does not exist" on iPhone and even in the editor where the ListGraph pathfinding works correctly.
     
  45. Unbannable25

    Unbannable25

    Joined:
    Sep 8, 2011
    Posts:
    2
    Is it possible to create our own Grid Graphs?

    I am creating a 2D isometric game based off of specific diagonal degrees, but the A* Grid Graph has to be exactly 90 degree rotated to face the camera and align with all of the flat 2D sprites. If I change the rotation to 30 degrees, I get the graph I want when looking at it from the editor, but in reality the lines have to move along the Z axis to eventually go to the graph and begin following along the Grid Graph's path.

    So rotating the graph doesn't work, it HAS to remain exactly at 90 degrees. I also wanted to know if we could add to it, such as creating a + inside the graph, so the path can stop in the middle of a diagonal and go Up/Down or Left/Right. My main need is simply to transform the Grid Graph from a perfect square, to a rectangle with diagonal path lines exactly at 30 degrees, without actually rotating the Grid Graph.

    This is what I need my graph to look like, from the left (a perfect square) to the right, a psuedo-tilted rectangle (it's not actually rotated, but only APPEARS to be because of the diagonal lines-- once more, I can't ACTUALLY rotate the graph, since I'm dealing with 2D sprites whose Z axis is always 0).



    Really, this is simple. It works perfect if I move along it manually, and just pretend 2 horizontal squares are a single tile. It goes from diagonal to diagonal. However, there is no actual path which goes from the top right of one screen, to the bottom left of the square beside it.

    [_][_] = "one" square, 1:2 pixel ratio, twice the horizontal per 1 vertical, a 30 degree diagonal.

    But it appears like this

    [X][X]

    And I need it to be like this

    [_X_]
    being two squares.

    Is there an easy way to do this or make custom Grid Graphs?
     
    Last edited: Sep 8, 2011
  46. Unbannable25

    Unbannable25

    Joined:
    Sep 8, 2011
    Posts:
    2
    I also had a question... how should I go about moving from "one line" in a path to the next?

    Right now I use GetAxis -1.0f to +1.0f for both horizontal and vertical movement, with Z always being 0.
    This is my 2D movement, but I want to change this to instead detect GetAxisRaw -1 or +1, and depending on the direction (of 8 possible directions based on Horizontal and Vertical AxisRaw) move the character EXACTLY "one line" from one end of the square to the next.

    Basically making a tile based movement. I am looking in the documentation to figure out movement along a path, but I am having a bit of a headache finding what I need to figure out how to tell my code to translate the character One_Line * Player_Speed.

    Am I just missing the reference in the Documentation for movement? I looked in the example demo Scene, but the movement for the "Player" is extremely complex and lengthy, and I don't really know where to start from there.

    I will continue to browse the documentation to figure it out, but a short explanation can save me a lot of time searching.

    Thanks!
     
  47. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Is there any reason increasing the heap size to 15000 would cause Unity to crash at runtime? Looks like it's when trying to do the scan. [IGNORE THIS - no longer an issue now I've made the changes below]

    I've managed to work around the issue with multithreading I was having by

    Code (csharp):
    1.  
    2. public void OnDrawGizmos () {
    3.  
    4.         if (active == null) active = this; // <--- added this as per your previous comment
    5.  
    Code (csharp):
    1.  
    2. public new static AstarPath active {
    3.         get {
    4.             if (!isActiveSet) {
    5.                 _active = GameObject.FindObjectOfType (typeof(AstarPath)) as AstarPath;
    6.                 isActiveSet = true; // <-- added this line
    7.  
     
    Last edited: Sep 10, 2011
  48. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hi

    I just released version 3.0.6 with Javascript support and C++ recast!
    Part of my changelog was lost, so I might have missed to add something.

    - 3.0.6
    - Added support for a C++ version of Recast which means faster scanning times and more features (though almost no are available at the moment since I haven't added support for them yet).
    - Removed the overload AstarData.AddGraph (string type, NavGraph graph) since it was obsolete. AstarData::AddGraph (Pathfinding::NavGraph) should be used now.
    - Fixed a few bugs in the FunnelModifier which could cause it to return invalid paths
    - A reference image can now be generated for the Use Texture option for Grid Graphs
    - Fixed an editor bug with graphs which had no editors
    - Graphs with no editors now show up in the Add New Graph list to show that they have been found, but they cannot be used
    - Deleted the \a graphIndex parameter in the Pathfinding::NavGraph::Scan function. If you need to use it in your graph's Scan function, get it using Pathfinding::AstarData::GetGraphIndex
    - Javascript support! At last you can use Js code with the A* Pathfinding Project! Go to A* Inspector-->Settings-->Editor-->Enable Js Support to enable it
    - The Dark Skin is now automatically used if the rest of Unity uses the dark skin(hopefully)
    - Fixed a bug which could cause Unity to crash when using multithreading and creating a new AstarPath object during runtime
     
  49. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hi Unbannable29

    There is actually a really simply solution, you've got to change about 0.3 lines of code!

    In the GridGenerator.cs script there is a function called GenerateMatrix (around line 268), in that function there is a line looking like this:
    Code (csharp):
    1. boundsMatrix.SetTRS (center,Quaternion.Euler (rotation),Vector3.one);
    Change that Vector3.one to something like
    Code (csharp):
    1. new Vector3 (0.5F,1,1)
    Where 0.5 is your new scaling factor.

    Then there is also a line looking like
    Code (csharp):
    1. matrix.SetTRS (boundsMatrix.MultiplyPoint3x4 (-new Vector3 (size.x,0,size.y)*0.5F),Quaternion.Euler(rotation), new Vector3 (nodeSize,1,nodeSize));
    Change the new Vector3 (nodeSize,1,nodeSize) to something like:
    Code (csharp):
    1. new Vector3 (nodeSize*0.5F,1,nodeSize)
    Where 0.5 is yet again your scale factor.

    Now you've got a scaled grid!

    I think I will have to add a built-in option for this...
     

    Attached Files:

    Last edited: Sep 11, 2011
  50. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    @Meanstreak

    Ok, can you post your settings for the List Graph? That would help me help you debug it.