Search Unity

Pathfinding for Point and Click movement

Discussion in 'Scripting' started by maltadirk, Apr 24, 2014.

  1. maltadirk

    maltadirk

    Joined:
    Mar 12, 2014
    Posts:
    43
    Hi,

    Could someone please give me a hand with pathfinding. I've purchased NavMeshPro (https://www.assetstore.unity3d.com/#/content/14079) as I thought it would do the trick for me but unfortunely no such luck.
    I would like a point-and-click movement for the Player. However its important that the player gets to the destination by finding the best route, avoiding obstacles such as Box Colliders. I've attached a screenshot of simple Scene to display better:

    $Pathfinding-Scene.jpg

    Once the Player clicks on a location in the level the Player (Green Cube) will move to the mouse point location, avoiding the Box Colliders.

    $Pathfinding-Example.jpg

    I will obviously have different scenes where varied size and location for the box colliders.
    I know probably the best tool is “A* Pathfinding” (http://arongranberg.com/astar/). I've check the following tutorial however it doesn't meet my required goal.


    Any advice would be greatly appreciated.
     
  2. Dameon_

    Dameon_

    Joined:
    Apr 11, 2014
    Posts:
    542
    Look up Unity 4.x Game AI Programming. It's a free ebook, and it covers a* pathfinding, as well as other pathfinding algorithms, and their application in Unity.
     
  3. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    why not just Unity's built in path-finding? Get the location of the click by casting a ray from the camera at the mouse cursor position on if(input.mousebuttondown(0)) then plug in your rays hitpoint info into your nav mesh agent destination of your green box
     
  4. maltadirk

    maltadirk

    Joined:
    Mar 12, 2014
    Posts:
    43
    Thanks @Dameon and @frankrs.
    I cant use Unity's built in path-finding as I don't have pro. I'm gonna go for A* Pathfinding Project
    Looks straightforward to use