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

Ideas on how to do this pathfinding?

Discussion in 'General Discussion' started by calmcarrots, Jun 7, 2014.

  1. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    654
    Hello, I have been developing this game for quite some time now and I have been trying real hard to avoid this pathfinding, but now I must complete it in order to finish my game (almost done, so excited!). First, a diagram:
    26426-untitled.png
    Let me explain real quick, each brown square is a door. The symbol above each door points to where the door will lead to. What / how do I get my AI from Room 1 to Room 4? I have no idea how to do this kind of pathfinding because I have never done anything similar.

    Let's please discuss this together so we can decide on how to approach this cryptic problem. Thanks for your time!
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    This is a simple waypoint network problem. You build a graph representing your world - each node is a room and each arc is a door - and then use an algorithm like A* to work out which rooms/doors you move through to get from A to B.
     
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,716
    Yep, A* is probably the way to go. There are faster methods, but unless your game has a network of 45,000 rooms that need to be pathed through, you should be fine.
     
  4. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    654
    Hmm, ok. So this will work if I only want the enemy to be at X = 5 constantly? And how would the teleportation work? When the AI hits the door, he would teleport to the other one, but he will also hit that other door and it will teleport him back.
     
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,789
    If you are teleporting you do not need pathfinding. You simply need to translate the transform position coordinates when triggering that portal to the new door and set the rotations according to the door rotation that he should be facing when teleported under conditions you create in if and else if statements. If that destination door has a trigger you may need to temporarily switch it off so he is not re-teleported.