Search Unity

A* Pathfinding Waypoints (aarku?)

Discussion in 'Scripting' started by drJones, May 22, 2006.

  1. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    I've been reading up on A* and have some questions regarding this post from aarku:

    http://forum.otee.dk/viewtopic.php?t=159&start=0&postdays=0&postorder=asc&highlight=pathfinding

    How would you have the nodes automatically "find" each other on startup? Is there a script attached to each that references all other nodes so they cast a ray (edge?) in the correct direction? Does each node have an individual name or are they possibly referenced by location only?

    It seems that with a decent amount of nodes you would have very long scripts and lots of manual setup if that is the case. Anybody have any advice?

    I'm also curious if you went any further with your pathfinding aarku.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    This is a script i was recently working on for an upcoming tutorial.
    It doesn't do A* path finding but does the autoconnecting.
     
  3. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    Hmm, I am getting this error:

    Assets/AutoWayPoint.js(40) error BCE0019: 'length' is not a member of 'Boo.Lang.List'.

    For this line of code:

    if (waypoints.length == 0)
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Sorry, change that line to be an upper case Length.
    (Should have tried it with 1.2.2 first)
     
  5. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    Strange, still getting the same error (only with capitalized 'Length' in the log) after changing to:

    if (waypoints.Length == 0)

    I'm using 1.2.2, any ideas?
     
  6. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    The script Joe posted is a JavaScript file not a Boo file. The error thinks it's boo. Perhaps you created a new Boo script and pasted it in instead of a new javascript? Either way, try just throwing the exact .js file Joe posted right into your project folder after changing the lenth to Lenth and then try it. (make sure to delete the old one.)

    -Jeremy
     
  7. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    hey jeremy

    it is a JS file (i did have to rename the download file itself from autowaypoint_121.js to AutoWayPoint.js though), but just to be sure i deleted it, fixed the 'L' in the original download and am still getting that error. is there something else that could be wrong?
     
  8. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Weird. Does the error still say Boo.Lang.List? If so it seems convinced that it's a Boo file. Joe would have to answer there.

    You could try creating a new js file in Unity, then pasting the code into it and making that change and see if you still get that error.

    EDIT: Also, in js it shouldn't matter what you name the file.

    -Jeremy
     
  9. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    yep same error, also tried the cut and paste as well.

    hmm, it gave me errors when i renamed the file. i don't remember exactly what it was but i think it said 'AutoWayPoint' is an invalid type (although i don't understand all of the script, it looks like it is referencing the other node instances so that made sense to me).

    well thanks for your help - i'm off to sleep now : )
     
  10. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    The Unity javascript implementation is actually based on the Boo runtime, so it uses the Boo.Lang.List class for its lists.

    As Boo.Lang.List inherits from .Net's ArrayList the attribute for getting the lenght is Count and not Length. (Why .Net uses different attributes for Arrays and ArrayLists is beyond me.)

    So it should read
    Code (csharp):
    1.  
    2. if (waypoints.Count)
    3.  
     
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Sorry for the confusion. I uploaded the fixed script.
     
  12. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    thank you, i'll try to get it working now.
     
  13. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    ok, i set up an AutoWayPoint prefab:

    -empty GO
    -box collider with is trigger checked
    -AutoWayPoint.js

    and placed a few in the scene. when i click on any/all of them i do not get the connecting lines. i do see a quick log line flash which says something like:

    Relative Movement (x:0.00000,x:0.00000,z:0.00000)

    sorry to keep bothering you, am i doing something wrong?
     
  14. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You dont need to add any trigger boxes because it doesn't use them at all.

    It only shows connections to the connected waypoints and not the lines for the entire graph.