Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iTween + A* Pathfinding = <3

Discussion in 'Made With Unity' started by GFX47, Dec 16, 2010.

  1. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    When pixelplacement's iTween meets Aron Granberg’s A* Pathfinding, you get a quick demo of what you can achieve with powerful and easy to use tools.

    With just 2 little scripts (basically 2 function calls, one for each tool), I easily managed to set a typical path finding system.

    Try the Web Player version (86 Ko) and/or download the project sources (1.5 Mo) here.

    Check comments in the Player.cs and KeyPoint.cs scripts for more details about this implementation.

    Big up to Bob “pixelplacement” Berkebile and Aron Granberg for their work! o//

     
    Last edited: Mar 22, 2011
  2. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    147
    mmmm. nice work.

    thanks for sharing ... I'll check your code at home.
     
  3. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    woooow thats great *love*

    but not for commercial project like my mmorpg :D
     
  4. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Why's that?
     
  5. mowgliworf

    mowgliworf

    Joined:
    Dec 16, 2010
    Posts:
    11
    Very cool! Are you using it in a game?
     
  6. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    cause i have to pay for a* pathfinding when i want to use it in my game (itll be free to play but i think that doesnt matter)

    or have u created all the code and ur so kind to let me use it for free?

    That would be great :D
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Aron Granbergs A* is free for non commercial and costs a nothing of $100 for commercial projects so really nothing to worry.
    You will pay more for the servers to host an ORPG / MORG, very likely already more per month unless you only get 20 players ie nothing in the range of MORPG at all
     
  8. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    hey dreamora

    First im 15 so i dont make my own money and my pocketmoney is used for a new pc...

    My server will be hosted at link 3 at vpslink.com...

    A friend of mine will pay the 240Š per year so u see: i dont have these 100$ and i cant take them from anywhere...

    Sry about that, this pahfinding would be one of the first things i would buy
     
  9. jobemakar

    jobemakar

    Joined:
    Jun 13, 2009
    Posts:
    74
    Robbilie,

    If you are after a free A* implementation you can use mine:
    http://jobemakar.wordpress.com/2008/08/16/a-astar-pathfinding/

    It is in ActionScript. Porting it to C# would likely take under an hour.

    If you wanted to learn more about the algorithm than what is posted I suggest Wikipedia, or check out my latest book:
    http://www.amazon.com/ActionScript-...=sr_1_1?ie=UTF8&s=books&qid=1292533515&sr=8-1

    In the book I use the A* algorithm in a virtual world. But again, it is all ActionScript. The concepts are the same in C# or AS. But obviously the syntax is different.

    Good luck.
     
  10. Thetal

    Thetal

    Joined:
    Nov 5, 2010
    Posts:
    92
    Codeproject.com have at least several C# implementations of A* pathfinding that are available under free licenses (BSD/MIT etc). Plus more could be found on net - just use "XNA" while searching. And there is jobemakar etc implementation. If someone really need it - he will find code.

    But that is a nice idea if someone would create a community port that is trully free to use. As for Granbergs A* fees, he don't publicly post his price - and "please contact me for price" sounds for me like price very well dependent on the project his code will be used, and could cost way more then a hundred $.
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    A* price is publically posted on the website, just read the rest of the block where he mentions the mail me for specific quotes etc :)
    Its $100 per commercial project actually so more than just affordable as already the editor part of an A* takes you days to pull off yourself
     
  12. Blacklight

    Blacklight

    Joined:
    Dec 6, 2009
    Posts:
    1,241
  13. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
  14. mowgliworf

    mowgliworf

    Joined:
    Dec 16, 2010
    Posts:
    11
    Thanks for sharing this. I'm definitely going to check it out this weekend.
     
  15. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Here is the project source in attachement for those who can't download it from original location.:cool:
     

    Attached Files:

  16. afalk

    afalk

    Joined:
    Jun 21, 2010
    Posts:
    164
    Cool example, I'll definitely give it a try :)
     
  17. wicked208

    wicked208

    Joined:
    Oct 25, 2010
    Posts:
    83
    thanks for this usefull tools, i am trying get to work on an uneven terrain, and mi player go throw the floor to find the point, how can i solve that?,
     
  18. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
  19. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Oh and don't forget to add collider to your walkable/unwalkable game objects!
    That's a mistake I often make... 5 minutes ago for instance XD
     
  20. wicked208

    wicked208

    Joined:
    Oct 25, 2010
    Posts:
    83
    thanks for answering i read the faq and the guide and my walkable player has collider but i have the same problem and i dont undestand why
     
  21. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Does your terrain have a mesh collider?
    Did you apply the same options than in my example?

    Anyway you should enable the "debug" option of your game object which holds the AStar component, you will see the walkable nodes in green colored dots linked by green segments (and unwalkable areas in red cubes).
     
  22. wicked208

    wicked208

    Joined:
    Oct 25, 2010
    Posts:
    83
  23. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Ok I think I get it now, try to decrease the node size in AStar configuration.
     
  24. wicked208

    wicked208

    Joined:
    Oct 25, 2010
    Posts:
    83
    thanks men, but doesnt work, i try a lot with options and none works, then i use the ai follow script and cliker scripts of the a pathfinding examples and its work, i think its a problem with the itween instruction in uneven terrain and then i changed the floor of your example for a terrain and works pefect, ohh men i think i m going to get crazy
     
  25. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
  26. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Here is a sexier version.

    iTween configuration has been tweaked to fit a more realistic trajectory (player’s orientation is better than previous version but still not totally satisfying).

    Below the interesting part of the main script (Player.cs):

    Code (csharp):
    1. iTween.MoveTo(gameObject, iTween.Hash
    2. (
    3.     "path", path,
    4.     "orienttopath", true,
    5.     "looktime", 1.0,
    6.     "lookahead", 0.05,
    7.     "axis", "y",
    8.     "easetype", iTween.EaseType.linear,
    9.     "time", iTween.PathLength(path) / moveSpeed,
    10.     "oncomplete", "OnMoveComplete"
    11. ));

    See iTween.MoveTo method’s documentation for more details about parameters.

    It also uses the soldier model from the Unity3D “Bootcamp” demo and its animations, that’s why the web player build and project archive are a bit heavier than before ^^;

    Try the Web Player version (4.4 Mo) and/or download the project sources (24.6 Mo) on my blog.
     
    Last edited: Mar 22, 2011
  27. Derydoca

    Derydoca

    Joined:
    May 13, 2010
    Posts:
    189
    I'm confused on why using iTween is necessary for this example. It can be achieved completely with the A* scripts unless I am missing anything.

    In a project I am prototyping right now I made the player able to click on a character, drag to where they want them to go and un-click and the A* scripts drives the character basically in the same way as your example.
     
  28. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Oh yeah of course iTween is not mandatory in this example but I thought it was interesting to show how you can do cool stuff by mixing those 2 great tools.
    There is even an "AI follow" component coming with AStar package allowing to move the character along the found path but it hasn't as many options as iTween.

    This example shows a really basic movement style but starting from there you can create pretty much whatever you want without requiring any knowledge about AStar path finding algorithm or character movements.

    I know this can "easily" be done once you have this knowledge, just thinking about those who don't have it or don't have the time to develop it from scratch ;)
     
  29. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    356
    I appreciate it. I'm sure I could figure it out, but time is precious, so any assistance is greatly appreciated.

    Plus, using iTween, you can do some nice easing, I suppose.
     
  30. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
  31. GFX47

    GFX47

    Joined:
    Dec 7, 2010
    Posts:
    124
    Last edited: Mar 22, 2011
  32. sennin

    sennin

    Joined:
    Feb 5, 2010
    Posts:
    26
    Awesome!