Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hi, I'm new to unity. Wondering if there is a scrip for this purpose

Discussion in 'Scripting' started by Riexy, Apr 12, 2014.

  1. Riexy

    Riexy

    Joined:
    Apr 12, 2014
    Posts:
    1
    I'm interested to see if there are any ready made scrips for this purpose. I'm looking for one script that enables the player to press different buttons to go to one of two or more different places, like illustrated in the picture under. A player stands at an area and presses A and goes to a specific location, or presses D to go to another location. Is this possible to do?

    $Namnlös.png


    Thanks,
    Riexy

    Edit: Sorry for spelling error in the title.
     
  2. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    I don't think there's any scripts out there that does specifically this, but you've pretty much written half of it already. :)
     
    Last edited: Apr 12, 2014
  3. P_Mason

    P_Mason

    Joined:
    Apr 6, 2014
    Posts:
    14
    Probably not one publicly available, but it'd be very easy to do.
     
  4. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182

    Look for a solution to the Traveling Sales Man problem then. Example solution: http://sourceforge.net/projects/tspsg/
     
    Last edited: Apr 13, 2014
  5. violinbg

    violinbg

    Joined:
    Mar 24, 2014
    Posts:
    79
    The easy way for you would be to use a State Machine.

    If you need lots and lots of different locations, you should implement a Binary Tree that has the positions as its nodes.
     
  6. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    He said each starting point has 2 or more choices but he could treat the choice to go to each node as a binary tree as that what all of computer science breaks down to ultimately anyway.

    So you can use the TSP to solve this problem at startup and create the needed state machine that has the solutions then.

    While I don't know the algorithm used maybe Unity NavMesh Agent does this but to calculate dynamically at run time you need Unity Pro.

    Sorry for sounding like a dummy but is TSP what all these 'A* AI' type solutions are using? I know Hippo or some other coders know this already.
     
    Last edited: Apr 13, 2014
  7. violinbg

    violinbg

    Joined:
    Mar 24, 2014
    Posts:
    79
    Yes, you are right. I actually tried to write a simple state-machine example to post here but it becomes too messy and it really is a bad choice for this.
    So yeah - Binary tree or other tree structure.